perf: reduce transcript and repeated-secret scan allocations - #2291
Open
suhaanthayyil wants to merge 2 commits into
Open
perf: reduce transcript and repeated-secret scan allocations#2291suhaanthayyil wants to merge 2 commits into
suhaanthayyil wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The newly added transcript read test file contains a Go syntax error (map[string][]byte{"full.jsonl": {}}) that will fail compilation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves performance in two hot paths: redaction (betterleaks repeated-secret handling) and checkpoint transcript blob reading, while adding benchmarks/tests to lock in output and format behavior.
Changes:
- Avoids repeated whole-input rescans in betterleaks by deduplicating findings by secret value per redaction call.
- Reads transcript blobs directly into pre-sized byte buffers (avoiding string round-trips) and preallocates chunk slices.
- Adds benchmarks and tests covering transcript read formats (base/legacy/empty/absent/chunk ordering) and repeated-secret redaction output.
File summaries
| File | Description |
|---|---|
| redact/redact.go | Deduplicates betterleaks findings by secret to prevent quadratic rescans/region growth. |
| redact/redact_bench_test.go | Adds a benchmark ensuring repeated-secret redaction remains output-preserving and allocation-efficient. |
| cmd/entire/cli/checkpoint/persistent.go | Reworks transcript blob reading to avoid Contents() string copies; preallocates chunk storage. |
| cmd/entire/cli/checkpoint/transcript_read_test.go | Adds tests/benchmarks for transcript read behavior across base/legacy/chunked formats. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+24
to
+27
| {name: "base", files: map[string][]byte{"full.jsonl": []byte("first\nsecond\n")}, want: []byte("first\nsecond\n")}, | ||
| {name: "legacy", files: map[string][]byte{paths.TranscriptFileNameLegacy: []byte("legacy\n")}, want: []byte("legacy\n")}, | ||
| {name: "empty", files: map[string][]byte{"full.jsonl": {}}, want: []byte{}}, | ||
| {name: "absent", files: map[string][]byte{}, want: nil}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://entire.io/gh/entireio/cli/trails/1241
Summary
Stringcall, avoiding duplicate whole-input searches and duplicate regions. For valid JSONL, this benefit is within one string field, such as a large tool result containing repeated request-log entries; equal values in separate fields or lines are not deduplicated together.File.Contents()strings; preallocate the chunk slice as well. The size hint covers both normal chunks and current unchunked shadow transcripts, up to a 1 GiB sanity ceiling. Above that, reads retain incremental growth. This ceiling is an allocation hint limit, not a read-size limit.configFingerprintVersionbump is needed. No API or configuration changes.Benchmarks
Original before/after medians from five runs with
-benchtime=500ms -benchmem, Go 1.26.6 on darwin/arm64 (Apple M5 Pro):The existing ClaudeFull2 fixture was effectively unchanged (167.462 → 163.730 ms).
Soph's review identified that the original 50 MB hint ceiling excluded current unchunked shadow transcripts. The new 64 MiB benchmark exercises that case. Fresh A/B medians comparing the previous PR implementation (
caf73c69b) with the amendment, using the same new benchmark, Go 1.26.6, Apple M5 Pro,GOMAXPROCS=4,-benchtime=20x -count=3 -benchmem:That is approximately 75% fewer allocated bytes. The 1 MiB and 8 MiB allocation counts remain unchanged. These benchmarks use real in-memory Git objects to isolate read/allocation costs; they are not end-to-end CLI speedup, peak-RSS, or production-frequency claims. The frequency of transcripts above 50 MB has not been measured here.
Benchmark output assertions check correctness. Performance comparisons are manual against a base ref; CI does not enforce an allocation or timing baseline.
Scope
agent.ReassembleJSONLpre-sizing, image-asset reads, and direct legacy fallback reads remain separate follow-ups, as requested in review.Validation
TestReadTranscriptFromTreeFormatsand focused redaction checks.mise run check: formatting, lint (0 issues), race-enabled unit/integration suite, and deterministic Vogon/Roger-Roger canaries; exit 0 in 241.96 seconds.golangci-lint config verifyseparately passed. Its online schema fetch was blocked inside the otherwise network-restricted full-check run; the actual lint analysis passed there.git diff --check.Vogon reports 56/56 and Roger-Roger 4/4; raw Vogon output includes four expected agent-specific skips. Reassembly and image-read follow-ups were not implemented.