Skip to content

perf: CLOCK eviction cache for file contents (#208)#259

Merged
justrach merged 1 commit intorelease/v0.2.57from
perf/208-clock-cache
Apr 13, 2026
Merged

perf: CLOCK eviction cache for file contents (#208)#259
justrach merged 1 commit intorelease/v0.2.57from
perf/208-clock-cache

Conversation

@justrach
Copy link
Copy Markdown
Owner

Summary

Replace Explorer.contents: StringHashMap([]const u8) (unbounded, 1.7GB peak RSS) with a fixed-size CLOCK eviction cache (4096 entries, ~200MB bounded).

  • ContentCache struct — 4096-slot array with CLOCK (second-chance) eviction algorithm
  • O(1) lookup via StringHashMap(u32) path-to-slot mapping
  • Hot files stay cached — reference bit set on access, cleared on sweep
  • Cold files evictedreadContentForSearch falls back to disk read on cache miss
  • explore: commitParsedFileOwnedOutline can leave word_index and trigram_index diverged on OOM #252 errdefer preserved — prior content duped before cache eviction so word_index restoration still works on OOM

Behavioral notes

  • Cache is bounded at 4096 entries. Repos with >4096 files will have cache misses during search, served from disk (~1ms latency vs 0 for cache hits)
  • All existing tests pass — no regressions in query correctness
  • releaseContents() now clears the cache instead of freeing a HashMap

Test plan

🤖 Generated with Claude Code

)

Explorer.contents was an unbounded StringHashMap holding all file contents
in memory (1.7GB peak RSS on 5K-file repos). Replace with a fixed-size
ContentCache using CLOCK (second-chance) eviction:

- 4096-entry slot array with reference bits
- O(1) path→slot lookup via StringHashMap
- Hot files (recently searched/read) stay cached
- Cold files evicted on sweep, readContentForSearch falls back to disk
- Prior content duped before cache eviction to preserve #252 errdefer
  word_index restoration on OOM

Expected: peak RSS drops from ~1.7GB to ~200MB on large repos while
maintaining identical query behavior (cache misses served from disk).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@justrach justrach merged commit 40183a0 into release/v0.2.57 Apr 13, 2026
1 check passed
@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 681555 659514 -3.23% OK
codedb_changes 108802 111421 +2.41% OK
codedb_deps 36512 29264 -19.85% OK
codedb_edit 23877 24882 +4.21% OK
codedb_find 138643 139711 +0.77% OK
codedb_hot 149530 151690 +1.44% OK
codedb_outline 432379 439976 +1.76% OK
codedb_read 143248 155444 +8.51% OK
codedb_search 281751 308222 +9.40% OK
codedb_snapshot 4588202 4519412 -1.50% OK
codedb_status 262000 261905 -0.04% OK
codedb_symbol 64578 63918 -1.02% OK
codedb_tree 88500 89777 +1.44% OK
codedb_word 91121 90222 -0.99% OK

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