Skip to content

Cache snapshot responses by store sequence#326

Merged
justrach merged 1 commit intorelease/0.2.579from
fix/snapshot-response-cache
Apr 26, 2026
Merged

Cache snapshot responses by store sequence#326
justrach merged 1 commit intorelease/0.2.579from
fix/snapshot-response-cache

Conversation

@justrach
Copy link
Copy Markdown
Owner

Summary

  • cache codedb_snapshot responses per default/project context using Store.currentSeq() as the freshness key
  • invalidate automatically when edits/indexing advance the store sequence
  • keep a 16 MB cap so very large snapshots do not stay pinned in memory
  • add regression coverage that repeated snapshots are reused and a changed store seq rebuilds the output

Local benchmark

Compared this branch against current origin/release/0.2.579 after #325:

  • codedb_snapshot: 602450 ns -> 68050 ns (-88.70%, -534400 ns)

This stacks on top of #325's JSON-generation improvement. After this change, repeated snapshot calls mostly pay for copying the cached response into the MCP output buffer.

Validation

  • zig build test
  • zig build
  • python3 scripts/run-bench-json.py /tmp/codedb-cache-head.json
  • base comparison via /tmp/codedb-release-cache-base at origin/release/0.2.579

@github-actions
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 480247 481286 +0.22% +1039 OK
codedb_changes 53588 54485 +1.67% +897 OK
codedb_deps 9279 8965 -3.38% -314 OK
codedb_edit 5978 6397 +7.01% +419 OK
codedb_find 62833 62174 -1.05% -659 OK
codedb_hot 93997 96909 +3.10% +2912 OK
codedb_outline 236476 240485 +1.70% +4009 OK
codedb_read 85215 85577 +0.42% +362 OK
codedb_search 175316 174314 -0.57% -1002 OK
codedb_snapshot 1339408 256474 -80.85% -1082934 OK
codedb_status 216829 220450 +1.67% +3621 OK
codedb_symbol 60583 59715 -1.43% -868 OK
codedb_tree 76959 79337 +3.09% +2378 OK
codedb_word 68132 68504 +0.55% +372 OK

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d99041bb0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp.zig
Comment on lines +1297 to +1299
const seq = store.currentSeq();
if (cache.appendIfFresh(alloc, out, seq)) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid caching snapshot before explorer catches up

handleSnapshot reads store.currentSeq() and uses it as the cache key before building the snapshot; that assumes explorer state is already synchronized with that seq. In the watcher path, incrementalDiff calls store.recordSnapshot(...) first and only then runs indexFileContent(...) (src/watcher.zig around lines 1001-1007), so a concurrent codedb_snapshot can cache pre-update explorer data under the new seq. Once this happens, later snapshot calls with that same seq will keep returning stale output until another write advances the seq, which is a user-visible correctness regression.

Useful? React with 👍 / 👎.

@justrach justrach merged commit ae587b5 into release/0.2.579 Apr 26, 2026
1 check passed
@justrach justrach deleted the fix/snapshot-response-cache branch April 26, 2026 03:41
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