perf(explore): searchSymbols binary-insert + complete the total order#649
Merged
Conversation
appendOne kept its K-bounded candidate buffer sorted by re-sorting the whole buffer on every accepted insert (O(K log K) compares per insert, plus a redundant final sort). The buffer is always sorted, so placement is a binary search + insert. The comparator also gains line_start as the final tiebreak: same-name same-file symbols compared equal, so their relative order fell out of hash-map iteration order — the residual nondeterminism the deterministic-ordering rewrite (#641) meant to eliminate. With the key ending in (path, line) and same-(path, line) deduped, ties are impossible and the sorted-insert invariant is total. A/B on this repo (exact/prefix/pattern/fuzzy/kind × max_results 200): payload bytes identical on every query; warm prefix query 3.1ms -> 896µs, name query 1.2ms -> 931µs (embedded dispatch timings). Gated bench: codedb_symbol +0.23% on the 21-file corpus (exact-name query barely exercises the insert path — the win scales with match count). zig build test: 23/23 steps, 869/873 (4 platform skips), incl. a new ordering test. e2e_mcp_test.py: 20/20. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Benchmark Regression ReportThresholds: 10.00% and 50,000 ns absolute delta
|
justrach
added a commit
that referenced
this pull request
Jul 5, 2026
Bump semver + npm to 0.2.5828 and round out the changelog entry with the six commits that landed after the draft was written: searchSymbols binary-insert + total-order tiebreak (#647, #649), word-index persist integer remap + chunked writes (#650), call-graph reverse adjacency precompute (#651), snapshot dual-write clone (#652), ranked-search line-offset resolution (#653), and scripts/bench-ab.sh (#654). No code changes beyond the version strings + CHANGELOG. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Second perf round, item 1 (smallest, highest-certainty from the 4-agent speedup survey).
What
searchSymbols'appendOnekept its K-bounded candidate buffer sorted by re-sorting the whole buffer on every accepted insert — O(K·log K) compares per insert with the default K=50/cap 200 — plus a redundant final sort. Since the buffer is always sorted, placement is a binary search + single insert (O(log K) compares, O(K) moves).The comparator also gains
line_startas the final tiebreak. Without it, same-name symbols in the same file (multiple nestedinits, overload-style patterns) compared equal, so their relative order still fell out of hash-map iteration order — the exact residual nondeterminism the deterministic-ordering rewrite (#641) meant to eliminate. With the key ending in (path, line) and same-(path, line) deduped, the order is total and the sorted-insert invariant is airtight.Evidence
prefix:"handle"3.1ms → 896µs,name:"main"1.2ms → 931µs.codedb_symbol+0.23% (the 21-file corpus exact-name case barely touches the insert path — the win scales with match count, i.e. prefix/fuzzy/glob on real indexes).zig build test: 23/23 steps, 869/873 (4 platform skips) including a new same-name-same-file ordering test. e2e: 20/20.🤖 Generated with Claude Code