From 1c6fcc7d6ace835ef6903ccf40a34dd3dbff3e87 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 25 Apr 2026 00:14:23 +0000 Subject: [PATCH] perf: replace Set with Uint8Array for fast dense integer tracking Co-authored-by: AhmmedSamier <17784876+AhmmedSamier@users.noreply.github.com> --- language-server/src/core/search-engine.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/language-server/src/core/search-engine.ts b/language-server/src/core/search-engine.ts index 39e03d7d..7111da5a 100644 --- a/language-server/src/core/search-engine.ts +++ b/language-server/src/core/search-engine.ts @@ -1649,7 +1649,8 @@ export class SearchEngine implements ISearchProvider { const heap = new MinHeap(maxResults, (a, b) => a.score - b.score); const searchContext = this.prepareSearchContext(query, scope); const preferredIndices = this.getPreferredIndicesForQuery(scope, query, indices); - const visited = preferredIndices.length > 0 ? new Set() : undefined; + // ⚡ Bolt: Fast dense integer tracking using Uint8Array instead of Set to avoid allocation overhead + const visited = preferredIndices.length > 0 ? new Uint8Array(this.items.length) : undefined; if (preferredIndices.length > 0) { this.searchWithIndices(preferredIndices, searchContext, heap, token, visited); @@ -1776,16 +1777,16 @@ export class SearchEngine implements ISearchProvider { context: ReturnType, heap: MinHeap, token?: CancellationToken, - visited?: Set, + visited?: Uint8Array, ): void { for (let j = 0; j < indices.length; j++) { if (j % 500 === 0 && token?.isCancellationRequested) break; const i = indices[j]; if (visited) { - if (visited.has(i)) { + if (visited[i] === 1) { continue; } - visited.add(i); + visited[i] = 1; } this.processItemForSearch(i, context, heap); } @@ -1795,12 +1796,12 @@ export class SearchEngine implements ISearchProvider { context: ReturnType, heap: MinHeap, token?: CancellationToken, - visited?: Set, + visited?: Uint8Array, ): void { const count = context.items.length; for (let i = 0; i < count; i++) { if (i % 500 === 0 && token?.isCancellationRequested) break; - if (visited?.has(i)) { + if (visited?.[i] === 1) { continue; } this.processItemForSearch(i, context, heap);