Skip to content

perf(explore): searchSymbols binary-insert + complete the total order#649

Merged
justrach merged 1 commit into
release/0.2.5828from
perf/symbol-binary-insert
Jul 4, 2026
Merged

perf(explore): searchSymbols binary-insert + complete the total order#649
justrach merged 1 commit into
release/0.2.5828from
perf/symbol-binary-insert

Conversation

@justrach

@justrach justrach commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Second perf round, item 1 (smallest, highest-certainty from the 4-agent speedup survey).

What

searchSymbols' 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 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_start as the final tiebreak. Without it, same-name symbols in the same file (multiple nested inits, 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

  • A/B on this repo (fresh servers, exact/prefix/pattern/fuzzy/kind filters, max_results up to 200): payload bytes identical on every query; embedded dispatch timings: warm prefix:"handle" 3.1ms → 896µs, name:"main" 1.2ms → 931µs.
  • Gated bench: 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

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>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 70918 73864 +4.15% +2946 OK
codedb_changes 6695 7008 +4.68% +313 OK
codedb_context 281075 260538 -7.31% -20537 OK
codedb_deps 297 298 +0.34% +1 OK
codedb_edit 44599 45435 +1.87% +836 OK
codedb_find 1937 1747 -9.81% -190 OK
codedb_hot 14333 14873 +3.77% +540 OK
codedb_outline 10524 11583 +10.06% +1059 NOISE
codedb_read 9377 10928 +16.54% +1551 NOISE
codedb_search 64049 70909 +10.71% +6860 NOISE
codedb_snapshot 73646 73735 +0.12% +89 OK
codedb_status 4940 5488 +11.09% +548 NOISE
codedb_symbol 47623 45316 -4.84% -2307 OK
codedb_tree 26297 26219 -0.30% -78 OK
codedb_word 6933 8889 +28.21% +1956 NOISE

@justrach justrach merged commit 21e8fcd into release/0.2.5828 Jul 4, 2026
2 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant