⚡ Bolt: Hoist SearchEngine object allocations#595
Conversation
Replaced inline array allocations and object instantiation within `searchRemainingItems` and `addUrlMatches` by hoisting them to reusable class members. This reduces garbage collection overhead in performance-critical hot paths. Co-authored-by: AhmmedSamier <[email protected]>
|
👋 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. |
📝 WalkthroughWalkthroughSearchEngine now reuses a priority marker array and URL-match ID set during burst searches. Documentation records the allocation-hoisting optimization. ChangesSearch Engine Allocation Reuse
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@language-server/src/core/search-engine.ts`:
- Around line 167-168: Update the index lifecycle methods setItems() and clear()
to reset burstUrlMatchIdsCache whenever the index is replaced or released,
preventing stale URL IDs from surviving. Add a regression test that performs a
URL burst search, clears or reloads the index, and verifies the cache does not
retain the previous IDs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4de7a6e2-27ad-4679-b8cb-3609fe5fb02b
📒 Files selected for processing (2)
.jules/bolt.mdlanguage-server/src/core/search-engine.ts
| private burstUrlMatchIdsCache: Set<string> = new Set(); | ||
| private reusablePriorityTypeIds = new Uint8Array(256); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Reset the reusable URL-ID cache with the index lifecycle.
The cache introduced on Line 167 retains endpoint IDs after setItems() and clear() release the index. It is only cleared when a later URL search starts, so a long-lived engine can keep stale IDs alive unnecessarily. Clear it in both lifecycle methods and add a regression test covering clear/reload after a URL burst search.
Proposed fix
async setItems(items: SearchableItem[]): Promise<void> {
+ this.burstUrlMatchIdsCache.clear();
this.items = items;
...
clear(): void {
+ this.burstUrlMatchIdsCache.clear();
this.items = [];
...
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private burstUrlMatchIdsCache: Set<string> = new Set(); | |
| private reusablePriorityTypeIds = new Uint8Array(256); | |
| async setItems(items: SearchableItem[]): Promise<void> { | |
| this.burstUrlMatchIdsCache.clear(); | |
| this.items = items; | |
| ... | |
| } | |
| clear(): void { | |
| this.burstUrlMatchIdsCache.clear(); | |
| this.items = []; | |
| ... | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@language-server/src/core/search-engine.ts` around lines 167 - 168, Update the
index lifecycle methods setItems() and clear() to reset burstUrlMatchIdsCache
whenever the index is replaced or released, preventing stale URL IDs from
surviving. Add a regression test that performs a URL burst search, clears or
reloads the index, and verifies the cache does not retain the previous IDs.
💡 What
Modified the
SearchEngineclass to eliminate inline object allocations inside hot search paths:searchRemainingItems: Replaced dynamicnew Uint8Array(256)allocation with a reusable class-levelreusablePriorityTypeIdsbuffer that is cleared and populated on each call.addUrlMatches: Replaced dynamicnew Set<string>()instantiation with a class-levelburstUrlMatchIdsCachethat is cleared on each call.🎯 Why
During burst search operations (e.g., executing searches for every keystroke), creating new
Uint8ArrayandSetinstances per stroke results in unnecessary allocations that trigger frequent garbage collection, slowing down rapid typing and UI responsiveness.📊 Impact
Measurably reduces the GC pause times and allocation overhead during rapid keystroke operations and burst searches, maintaining high throughput in large workspaces.
🔬 Measurement
Tests in the
language-serverpassed, ensuring the exact same matching behaviors and results remain. The performance optimization can be seen in memory profiles that show fewer temporary arrays and sets being allocated and collected when the search functions are invoked continuously.PR created automatically by Jules for task 466437973161491164 started by @AhmmedSamier
Summary by CodeRabbit