Repository navigation
perf(viewer): avoid copying owned JSONL records - #1967
Merged
lizhengfeng101 merged 1 commit intoNov 19, 2026
Merged
Conversation
Contributor
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
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.
Description
Listing saved review sessions scans every JSONL record to build each summary.
readJSONLLinesusesbufio.Reader.ReadBytes, which returns an independently allocated record, butpeekSessioncopies that complete record again just to retain the final line. Large LLM response records therefore incur an unnecessary full-record allocation and copy even though only the last record is needed after the scan.Retain the owned record directly and document the callback's ownership contract. Session parsing, counts, final-record handling, and partial-read error behavior stay the same.
Type of Change
How Has This Been Tested?
A retained-record test keeps every callback slice and verifies it after subsequent reads, including a record longer than the reader buffer, CRLF, and an unterminated final record. A benchmark calls the real
ListSessionspath and checks the resulting comment count, file count, duration, and completed status on every iteration. Both the ownership test and benchmark assertions pass on the original and updated implementations.Allocation measurements for a session containing 64 LLM response records, with a session start, a finding, and a final manifest (Go 1.26.11, linux/amd64, one logical processor; median of five runs):
This removes one allocation per record and about one third of allocated bytes in these workloads. Timing was noisy in the shared environment, so the claim is limited to allocation reduction.
make check— passed.make test PACKAGES=./internal/viewer— passed, including the race detector.make test PACKAGES="./internal/viewer -run=NoTests -bench=BenchmarkListSessionsResponseRecords -benchtime=200ms -count=5 -race=false"— before/after benchmarks passed; the race detector is disabled only for measurement.make coverage— the complete unit-test suite passed, with 91.7% overall coverage (90% required).make build— passed.The inherited telemetry sampler was explicitly set to
always_onfor the test suite. The requiredocr review --audience agent --background "..."command was attempted, but could not start because no LLM endpoint is configured in the environment.Checklist
AI/LLM disclosure: OpenAI ChatGPT (GPT-6 Astra Pro).