⚡ Bolt: [performance improvement] avoid string[] allocations in GetTaskSearchTokens - #128
Conversation
…skSearchTokens Replaced `string.Split` with `ReadOnlySpan<char>.SplitAny` in `GetTaskSearchTokens` methods (RootPaletteSearchIndex.cs and WorkspaceRepositorySnapshot.cs) to prevent array allocations and intermediate string creations on frequent searches.
|
👋 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. |
📝 WalkthroughWalkthroughChangesTask search tokenization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 8✅ Passed checks (8 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
💡 What:
Replaced
string.Splitwith.AsSpan().SplitAny([' ', '\t', '\r', '\n'])inGetTaskSearchTokensinsideRootPaletteSearchIndex.csandWorkspaceRepositorySnapshot.cs. Used aHashSet<string>and passedReadOnlySpan<char>into helper methods to process tokens and filter out verbs before allocating any strings.🎯 Why:
The
GetTaskSearchTokensmethod is called repeatedly during search index queries and autocomplete scenarios as the user types. The originalstring.Splitcreates astring[]of all separated chunks and allocates an intermediatestringfor every piece before processing, causing high GC pressure.📊 Impact:
Eliminates intermediate array and string allocations. Significantly reduces GC pressure during search palette typing operations.
🔬 Measurement:
Compare memory allocations using dotMemory or Visual Studio Profiler while rapidly typing queries with spaces into the root palette or workspace search. The overall Gen 0 collections should be reduced.
PR created automatically by Jules for task 572405395171916712 started by @mta-babel
Summary by cubic
Cut GC allocations in task search tokenization by using span-based splitting and deferring string creation. This reduces stutter while typing in the root palette and workspace search.
string.Splitwithquery.AsSpan().SplitAny([' ', '\t', '\r', '\n'])inGetTaskSearchTokensforRootPaletteSearchIndexandWorkspaceRepositorySnapshot; process tokens asReadOnlySpan<char>, trim punctuation, and filter verbs before allocating.HashSet<string>and return astring[]; behavior is unchanged.Written for commit 71f3804. Summary will update on new commits.