Skip to content

perf: consolidate grep cache index#109

Merged
sorafujitani merged 1 commit into
mainfrom
perf/grep-cache-index
Jul 3, 2026
Merged

perf: consolidate grep cache index#109
sorafujitani merged 1 commit into
mainfrom
perf/grep-cache-index

Conversation

@sorafujitani

Copy link
Copy Markdown
Owner

Summary

  • replace per-transcript grep cache files with one per-cache-dir index.json
  • store v2 cache records as a joined text payload plus fragment count
  • preserve fragment-boundary matching by splitting cached text before TextsContain
  • treat v1/no-version records as misses and tolerate corrupt indexes by falling back to extraction
  • expand the repeated-query benchmark to 512 sessions

Fixes #102

Benchmark

Baseline was measured on origin/main with only the benchmark session count changed to 512.

Command:

go test -bench=BenchmarkFilterRepeatedQuery -benchmem ./internal/grep -count=10

benchstat /tmp/ccsession-102-before-512.txt /tmp/ccsession-102-after.txt:

FilterRepeatedQuery/direct-read-12  462.83m ± 178%  18.35m ± 4%  -96.04% (p=0.000 n=10)
FilterRepeatedQuery/warm-cache-12    28.046m ± 777%  1.294m ± 5%  -95.39% (p=0.000 n=10)

FilterRepeatedQuery/direct-read-12  41.67Mi ± 0%  41.27Mi ± 0%   -0.97% (p=0.000 n=10)
FilterRepeatedQuery/warm-cache-12   6490.5Ki ± 0% 378.0Ki ± 0%  -94.18% (p=0.000 n=10)

FilterRepeatedQuery/direct-read-12  19.52k ± 0%  15.43k ± 0%  -20.96% (p=0.000 n=10)
FilterRepeatedQuery/warm-cache-12   13.367k ± 0%  3.636k ± 0%  -72.80% (p=0.000 n=10)

The direct-read timing is noisy because the benchmark deliberately points the cache dir at a file to disable caching. The main target is warm-cache grep reloads, which now read one index instead of one cache file per session.

Verification

go test ./...
go vet ./...
golangci-lint run
gofmt -l $(git ls-files '*.go')
git diff --check

@sorafujitani sorafujitani merged commit 576ff98 into main Jul 3, 2026
7 checks passed
@sorafujitani sorafujitani deleted the perf/grep-cache-index branch July 3, 2026 06:03
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.

perf: reduce per-keystroke grep cache overhead (N file opens + full-text unmarshal)

1 participant