diff --git a/vscode-extension/src/slash-command-service.ts b/vscode-extension/src/slash-command-service.ts index 2c2de5a..4c499ef 100644 --- a/vscode-extension/src/slash-command-service.ts +++ b/vscode-extension/src/slash-command-service.ts @@ -286,6 +286,9 @@ export class SlashCommandService { private sortResults(results: SlashCommand[], query: string): void { const lowerQuery = query.toLowerCase(); + // ⚡ Bolt: Pre-compute Set for O(1) recency lookups instead of O(N) Array.includes during sort + const recentSet = new Set(this.recentlyUsed); + results.sort((a, b) => { const aExact = a.name === lowerQuery; const bExact = b.name === lowerQuery; @@ -293,8 +296,8 @@ export class SlashCommandService { if (aExact && !bExact) return -1; if (!aExact && bExact) return 1; - const aRecent = this.recentlyUsed.includes(a.name.toLowerCase()); - const bRecent = this.recentlyUsed.includes(b.name.toLowerCase()); + const aRecent = recentSet.has(a.name.toLowerCase()); + const bRecent = recentSet.has(b.name.toLowerCase()); if (aRecent && !bRecent) return -1; if (!aRecent && bRecent) return 1;