⚡ Bolt: Reuse Uint8Array and fast O(K) reset for visited tracker#414
⚡ Bolt: Reuse Uint8Array and fast O(K) reset for visited tracker#414AhmmedSamier wants to merge 1 commit intomasterfrom
Conversation
…rch engine 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. |
📝 WalkthroughWalkthroughThe search engine is refactored to eliminate per-search allocations of a visited tracking array by reusing an instance-level ChangesSearch Engine Deduplication Buffer Reuse
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 186-187: The clear() method currently doesn't reset the reusable
visited state, leaving a previously large Uint8Array retained; update the
clear() implementation to explicitly reset the visitedBuffer to a new
Uint8Array(0) and visitedTracker to an empty array (visitedBuffer = new
Uint8Array(0); visitedTracker = [];), alongside the existing cache/field resets
so the engine truly frees that memory when clearing state.
🪄 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
Run ID: 28d062d2-9c1f-413a-acdd-baa042fd7c94
📒 Files selected for processing (3)
language-server/apply_patch.shlanguage-server/benchmarks/results_burst.jsonlanguage-server/src/core/search-engine.ts
| private visitedBuffer: Uint8Array = new Uint8Array(0); | ||
| private visitedTracker: number[] = []; |
There was a problem hiding this comment.
Reset reusable visited state when clearing engine state.
clear() (Line 756 onward) doesn’t reset the new visitedBuffer/visitedTracker, so a previously large Uint8Array can stay retained after a full clear. Please clear these alongside other caches.
💡 Proposed fix
clear(): void {
this.items = [];
@@
this.inactiveFileItems = [];
+ this.visitedBuffer = new Uint8Array(0);
+ this.visitedTracker = [];
this.invalidateDerivedCaches();
}🤖 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 186 - 187, The
clear() method currently doesn't reset the reusable visited state, leaving a
previously large Uint8Array retained; update the clear() implementation to
explicitly reset the visitedBuffer to a new Uint8Array(0) and visitedTracker to
an empty array (visitedBuffer = new Uint8Array(0); visitedTracker = [];),
alongside the existing cache/field resets so the engine truly frees that memory
when clearing state.
💡 What:
Replaced the per-search allocation of
new Uint8Array(this.items.length)inSearchEngine.performUnifiedSearchwith a reusable, class-levelvisitedBufferand avisitedTrackerarray for fast O(K) clearing.🎯 Why:
In the hot path of searching (especially burst/continuous searching), allocating a large array (proportional to total workspace items) and subsequently garbage collecting it creates significant memory pressure and pauses.
📊 Impact:
Reduces array allocation overhead on every search query to zero. The buffer is now cleared in O(K) time where K is only the number of items actually visited during the search, not the total size of the workspace items array. The burst search benchmark for "No match" scenario stays basically the same or slightly faster while avoiding huge memory swings.
🔬 Measurement:
Run
cd language-server && bun run benchmarks/search_burst.bench.tsand verify memory usage metrics/execution times.PR created automatically by Jules for task 3281649880735625941 started by @AhmmedSamier
Summary by CodeRabbit
Performance Improvements
Tests