Repository navigation
perf(global-search): cache normalized fields across keystrokes - #3960
Merged
kev1n77 merged 1 commit intoNov 19, 2026
Merged
Conversation
Raing5Days
marked this pull request as ready for review
November 17, 2026 03:12
scoreTextMatch runs once per candidate row per keystroke, and it re-derived every row's lowercase form on every call: `rawField.trim().toLocaleLowerCase()` for each field, plus an allocation for the multi-token working list. Fields do not change between keystrokes, so the normalized form is now looked up from a small bounded cache keyed by the raw string, the working list is only built for multi-token queries, and the per-token scoring loop no longer spreads a mapped array into Math.max. Measured 0.617 us -> 0.320 us per call for a realistic workload (query "provider" against a row's title, subtitle and keywords); behaviour is unchanged.
Raing5Days
force-pushed
the
openbitfun/search-match-field-cache
branch
from
November 17, 2026 03:47
ad7b1f7 to
b574079
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scoreTextMatchruns once per candidate row per keystroke. Every call re-derived the same normalized strings:rawField.trim().toLocaleLowerCase()ran for every field of every row on every keystroke, although field text does not change between keystrokes while the query does.Math.max, allocating an argument list per token per row.Fields now come from a small bounded cache keyed by the raw string (empty results are not cached, and the cache clears past 1024 entries), the working list is built only when the query has more than one token, and the scoring loop accumulates in a loop. Behaviour is unchanged;
searchMatching.test.tsand an equivalence check against the previous implementation (15 queries × 8 field sets, warm and cold cache, plus churn past the cache cap) agree on every input.The same change-set also skips entering the fence regex in
sanitizeInlineAiMarkdownResponsewhen a streamed reply does not start with a fence — the pattern is anchored at^, so the match could not succeed, butString.matchstill built its match state. Output is identical across 27 hand-written and 336 generated fence/body/tail combinations.Validation
node scripts/run-vitest.mjs run src/app/global-search/searchMatching.test.ts src/tools/editor/meditor/utils/inlineAi.test.ts— 9 passedpnpm run type-check:web— passedscoreTextMatch('provider', [title, subtitle, keywords]): 0.617 µs → 0.320 µs per call (median of 3 runs after the change, worst call 0.372 µs); the budget derived from the pre-change baseline was 0.432 µssanitizeInlineAiMarkdownResponseon a 1.7 KB reply: 0.073 µs → 0.040 µs per callpnpm run check:web— fails onmainat theminiapp-chrome-themegenerated-artifact check; the failing output is identical with and without this diffBoth numbers are per-call costs under these workloads, not frame times. The search benchmark passes a short query and three short fields, which is how the federated search engine calls it; the sanitizer benchmark passes a 1.7 KB reply.
Generated with OpenBitFun