Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@

**Learning:** In hot paths that traverse an Abstract Syntax Tree (AST), using dynamic string manipulations like `!parent.type.toLowerCase().includes('class_declaration')` inside a `while` loop creates redundant memory allocations (garbage collection overhead) and slows down the loop significantly. The string `.toLowerCase()` allocation happens on every single node iteration.
**Action:** Replace dynamic string manipulations with a static, pre-allocated `Set` of exact node names (e.g., `'class_declaration'`, `'class_definition'`, `'class'`) and use `.has(parent.type)` to achieve O(1) lookups and eliminate string allocation entirely in the loop.

## 2026-05-06 - [Eliminate Tracking Arrays in O(N) Fallbacks]

**Learning:** When performing a final multi-pass search or filtering fallback that iterates over the entire dataset (e.g., `searchRemainingItems`), allocating an O(N) tracker array (like `new Uint8Array(items.length)`) and running pre-population loops to mark previously visited items introduces unnecessary memory allocation, garbage collection pressure, and O(N) initialization overhead.
**Action:** Instead of dynamically tracking what has already been processed, evaluate the item's inherent metadata or pre-computed lookup maps (like `ID_TO_SCOPE` combined with `this.itemTypeIds`) to determine if it belongs to an already-processed category (e.g., `priorityScopes.includes(scope)`). This provides an O(1) condition check and completely eliminates the need for visited tracking arrays in the final sweep.
29 changes: 29 additions & 0 deletions language-server/benchmarks/results_burst.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"name": "Burst Search \"App\" (Matches found)",
"avgMs": 0.021544649999999593,
"totalMs": 2.154464999999959,
"minMs": 0.005148999999960324,
"maxMs": 0.18533700000000408,
"p95Ms": 0.07276600000000144,
"stdDevMs": 0.03259625219587125
},
{
"name": "Burst Search \"Zzz\" (No match)",
"avgMs": 18.35233173,
"totalMs": 1835.233173,
"minMs": 13.984671000000162,
"maxMs": 33.71546699999999,
"p95Ms": 26.035532999999987,
"stdDevMs": 3.8124350347516467
},
{
"name": "Burst Search \"S\" (Many matches)",
"avgMs": 0.5702139400000032,
"totalMs": 57.02139400000033,
"minMs": 0.4487290000001849,
"maxMs": 1.173258999999689,
"p95Ms": 0.6901020000000244,
"stdDevMs": 0.10386148486978344
}
]
17 changes: 4 additions & 13 deletions language-server/src/core/search-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2340,21 +2340,12 @@ export class SearchEngine implements ISearchProvider {
results: SearchResult[],
token?: CancellationToken,
): void {
// ⚡ Bolt: Fast Unique Tracking Optimization
// Replace Set<number> with a pre-allocated Uint8Array
const searchedIndices = new Uint8Array(this.items.length);
for (let j = 0; j < priorityScopes.length; j++) {
const indices = this.scopedIndices.get(priorityScopes[j]);
if (indices) {
for (let k = 0; k < indices.length; k++) {
searchedIndices[indices[k]] = 1;
}
}
}

// ⚡ Bolt: Eliminate Tracking Array Allocation
// Check the item's inherent scope instead of allocating an O(N) visited array
for (let i = 0; i < this.items.length; i++) {
if (results.length >= maxResults || token?.isCancellationRequested) break;
if (searchedIndices[i] === 0) {
const scope = ID_TO_SCOPE[this.itemTypeIds[i]];
if (!priorityScopes.includes(scope)) {
processItem(i);
}
}
Expand Down
Loading