You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(session): reuse JSONL buffers while loading saved reviews - #2063
Inspecting or resuming a saved review reads every JSONL record, including large LLM responses that the summary and checkpoint decoders do not retain. Both session readers currently use ReadBytes, which allocates a new complete line and copies the buffered fragments for each response.
Use one private record reader for these two immediate-decoding paths. Short records borrow the input buffer; long records use an overflow buffer reused within that file traversal. JSON decoding still produces independently owned metadata and checkpoints. A traversal retains its largest overflow buffer until it finishes; there is no pool or cache shared between sessions.
The existing parsing decisions remain at the call sites: display accepts a valid unterminated final record, resume drops that tail as a torn write, strict resume rejects malformed complete records, and review resume skips them. The viewer's retained-record reader is unchanged.
Type of Change
Performance improvement
How Has This Been Tested?
The functional test writes a complete review through SessionHistory, including long checkpoints on either side of 32 large response records and a final coverage manifest. It checks detail output, retained comment contents, both resume modes, reusable checkpoints, CRLF, a long unterminated tail, and a long malformed complete line. These public-path checks pass before and after the change. A reader contract test compares records and errors against ReadBytes with short reads, buffer boundaries, invalid bytes, EOF returned with data, and injected read errors.
The benchmark uses actual saved sessions containing 64 response records and verifies complete summary or resume metadata on every iteration. Median of five runs with Go 1.26.10, linux/amd64, GOMAXPROCS=1, and a 150 ms benchmark duration:
Response content per record
Loader
Before B/op
After B/op
Before allocs/op
After allocs/op
1 KiB
Summary
326,057
201,057
1,657
1,523
1 KiB
Resume
272,249
147,249
1,516
1,382
64 KiB
Summary
9,186,751
423,589
2,937
1,528
64 KiB
Resume
9,132,946
369,780
2,796
1,387
256 KiB
Summary
34,524,728
1,324,800
6,138
1,533
256 KiB
Resume
34,470,898
1,270,997
5,996
1,392
A separate Linux probe generates its fixtures in another process and compares five fresh reader processes per implementation, checking identical SHA256 hashes of the complete decoded results. With 64 responses of 256 KiB, median peak RSS was 17,224 to 13,512 KiB for summary and 16,968 to 13,384 KiB for resume. With 1 MiB responses, allocated bytes fell from about 136 MB to 5.4 MB, but peak RSS changed only slightly. The performance claim is reduced allocation volume; timing and peak RSS depend on the workload and runtime.
make license-add check build — passed.
Before/after public-path tests and allocation benchmarks — passed; race detection disabled only for benchmark measurement.
Full make test with the race detector — passed across all 28 packages.
make coverage — passed, 91.5% overall coverage (90% required); internal/session is 90.7%.
The inherited telemetry sampler is set to always_on for the test process.
The required ocr review --audience agent --background "..." command was attempted, but could not start because no valid LLM endpoint is configured.
Updated the branch to 591bff959c6667b739acfea79e4756b5d2f8b781, integrating current main c445fb4e377d and resolving the list.go conflict. The resolution keeps main's readSessionRecords(io.Reader, ...) entry point and uses the reusable JSONL reader inside it; the original parsing and retained-record behavior remain covered by the existing tests. GitHub now reports no merge conflicts.
Validation ran on this exact commit with Go 1.26.11 on Linux before updating the PR:
make check
Focused race tests for internal/session, internal/viewer and cmd/opencodereview
Full make test with the race detector
make coverage: 91.6% overall against the 90% threshold; internal/session: 91.0%
make build
All passed. Workflow, source identity and complete logs. The allocation/RSS measurements in the description remain the original before/after measurements; they were not remeasured for this integration commit.
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
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
Inspecting or resuming a saved review reads every JSONL record, including large LLM responses that the summary and checkpoint decoders do not retain. Both session readers currently use
ReadBytes, which allocates a new complete line and copies the buffered fragments for each response.Use one private record reader for these two immediate-decoding paths. Short records borrow the input buffer; long records use an overflow buffer reused within that file traversal. JSON decoding still produces independently owned metadata and checkpoints. A traversal retains its largest overflow buffer until it finishes; there is no pool or cache shared between sessions.
The existing parsing decisions remain at the call sites: display accepts a valid unterminated final record, resume drops that tail as a torn write, strict resume rejects malformed complete records, and review resume skips them. The viewer's retained-record reader is unchanged.
Type of Change
How Has This Been Tested?
The functional test writes a complete review through
SessionHistory, including long checkpoints on either side of 32 large response records and a final coverage manifest. It checks detail output, retained comment contents, both resume modes, reusable checkpoints, CRLF, a long unterminated tail, and a long malformed complete line. These public-path checks pass before and after the change. A reader contract test compares records and errors againstReadByteswith short reads, buffer boundaries, invalid bytes, EOF returned with data, and injected read errors.The benchmark uses actual saved sessions containing 64 response records and verifies complete summary or resume metadata on every iteration. Median of five runs with Go 1.26.10, linux/amd64,
GOMAXPROCS=1, and a 150 ms benchmark duration:A separate Linux probe generates its fixtures in another process and compares five fresh reader processes per implementation, checking identical SHA256 hashes of the complete decoded results. With 64 responses of 256 KiB, median peak RSS was 17,224 to 13,512 KiB for summary and 16,968 to 13,384 KiB for resume. With 1 MiB responses, allocated bytes fell from about 136 MB to 5.4 MB, but peak RSS changed only slightly. The performance claim is reduced allocation volume; timing and peak RSS depend on the workload and runtime.
make license-add check build— passed.make testwith the race detector — passed across all 28 packages.make coverage— passed, 91.5% overall coverage (90% required);internal/sessionis 90.7%.always_onfor the test process.The required
ocr review --audience agent --background "..."command was attempted, but could not start because no valid LLM endpoint is configured.Core contribution owner: @Afloat16.
AI/LLM disclosure required by this repository: ChatGPT (OpenAI GPT-6 Astra Pro).