Skip to content

bench: Go benchmarks for store, code index, survey, grammar, parse, memory - #45

Open
jmylchreest wants to merge 2 commits into
mainfrom
bench/store-paths
Open

bench: Go benchmarks for store, code index, survey, grammar, parse, memory#45
jmylchreest wants to merge 2 commits into
mainfrom
bench/store-paths

Conversation

@jmylchreest

Copy link
Copy Markdown
Owner

Benchmark suite for the store / code-index / survey hot paths

Adds 18 benchmarks across 6 packages, measuring the scan / commit / retrieval paths. All construct their own stores in b.TempDir() with in-memory synthetic fixtures (mock CodeGrapher/CodeSearcher reused from existing tests) — zero real-data access, zero network. No existing files modified.

Files (all new)

File Benchmarks
pkg/store/store_bench_test.go BoltStoreAddMemories, SearchMemories{,WithScore}, ListMemories
pkg/store/code_bench_test.go CodeIndexFileBatch, AddSymbol, SearchSymbols{,References}, GetFileSymbols, ClearFile
pkg/survey/survey_bench_test.go RunChurn, RunEntrypoints, BuildCallGraph, ComputeFreshness
pkg/grammar/grammar_bench_test.go ScanProject, ScanDetail, NormaliseLang
pkg/code/code_bench_test.go TokenizeFile{Go,TS}, ParseFile{Go,TS}
pkg/memory/memory_bench_test.go ScoreMemory{,Detailed}

Key findings (devbox, -benchmem -count=3)

  • Writes are fsync-bound (~9–25 ms per bbolt commit), not CPU-bound. IndexFileBatch is ~27× cheaper per record than AddSymbol (~0.7 ms vs ~19 ms per symbol) — empirically validates the batching design.
  • Retrieval is index-bound: code symbol search ~2.7 ms over 3k symbols; reference lookup ~10 µs (bbolt prefix scan); GetFileSymbols ~250 µs (JSON decode dominated).
  • Parsing is the scan CPU hotspot (~0.65 ms/file) but storage gates indexing (~22 ms commit ≫ parse).
  • Language detection ~97 ns and memory scoring ~330 ns, both alloc-free.
  • Caveat: absolute store numbers reflect this VM's high-fsync-latency disk; the relative ratios are the durable signal.

Verification

  • go vet — clean, exit 0
  • Smoke test (-benchtime=1x -count=1) — all 18 benchmarks PASS
  • Every benchmark builds its own store in b.TempDir() (local /tmp, not NFS)

Co-authored-by: Hermes jmylchreest+hermes@gmail.com

…e, memory paths

New benchmark files (6) measuring the hot paths across aide:
- pkg/store: bolt+bleve memory commit/retrieval, code index batch/symbol/
  search/clear (per-op and batched)
- pkg/survey: churn, entrypoints, call graph, freshness against a scratch
  repo
- pkg/grammar: full project scan (ScanProject/ScanDetail), language normalise
- pkg/code: tokenize vs parse cost for Go + TypeScript
- pkg/memory: score memory

All benchmarks construct their own stores in b.TempDir() and use only
in-memory synthetic fixtures (mock grapher/searcher reused from existing
tests) — zero real-data access, zero network. No existing files modified.

Measurement pass (devbox, -benchmem -count=3) highlights:
- write paths are fsync-bound (~9-25ms/commit); IndexFileBatch is ~27x
  cheaper per record than AddSymbol, confirming the batching rationale
- retrieval is index-bound: symbol search 2.7ms/3k corpus, ref lookup ~10us
- parsing ~0.65ms/file is the scan CPU hotspot; storage still gates indexing
- language detection ~97ns alloc-free; memory scoring ~330ns alloc-free

Co-authored-by: Hermes <jmylchreest+hermes@gmail.com>
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… rotation

AddSymbol and BoltStoreAddMemories previously wrote N fresh records into one
growing store, so b.N iterations measured 'add to an ever-larger index'
(fragmented bleve segments) rather than steady-state commit cost. Profile
confirmed scorch.mergerLoop absorbing ~72% of allocations purely from this.

Rotate a fixed pool (512 symbols / 256 memories) and give each element a
stable deterministic ID. AddSymbolTx/AddMemory only mint a ULID when the ID
is empty, so a non-empty ID makes each op overwrite the same bbolt key and
bleve doc: the index stays at a stable size and per-op cost stops growing.

Verified: ns/op varies only +-15% across a 512x span of b.N, and is flat
even after 2 full pool laps (AddSymbol 25.9M ns/op at 1024x, AddMemories
33.0M ns/op at 512x) — had ULIDs still been minted, a 2x record count would
show growing cost. Steady-state upsert achieved.

Co-authored-by: Hermes <jmylchreest+hermes@gmail.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