⚡ Bolt: [SearchEngine] Optimize RouteMatcher regex precomputation with single-pass string parsing#242
Conversation
…ing in RouteMatcher Replaced 5 consecutive `replaceAll` regex operations in `RouteMatcher.getOrCompileCache` with a single-pass string parsing and substitution loop. Benchmarking showed an improvement of ~4.7x for precomputing ASP.NET route templates. This optimization reduces string allocations and regex compilations during indexing/search. Co-authored-by: AhmmedSamier <17784876+AhmmedSamier@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Replaced 5 consecutive
replaceAllregex operations inRouteMatcher.getOrCompileCachewith a single-pass string parsing loop.🎯 Why: The
RouteMatcherconverts ASP.NET route templates to standard regexes to search for Endpoints. Using multiple.replaceAlloperations on string inputs causes multiple intermediate string allocations and regex execution overhead, acting as a bottleneck when calculating paths for search items or index generation.📊 Impact: Approximately 4.7x faster template to regex conversion (benchmarked at ~187ms vs ~39ms for 100k iterations). This reduces CPU and memory overhead when scanning and matching endpoint strings.
🔬 Measurement: Run
bun test src/core/route-matcher.test.ts src/core/route-matcher-regression.test.tswithin thelanguage-serverdirectory to verify functionality remains unchanged. You can also benchmark withperf_hooksloop overstringApproachvs originalregexApproach.PR created automatically by Jules for task 8373083886981394089 started by @AhmmedSamier