Skip to content

perf(viewer): avoid copying owned JSONL records - #1967

Merged
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
Afloat16:perf/viewer-summary-record-allocation
Nov 19, 2026
Merged

lizhengfeng101 merged 1 commit into
alibaba:mainfrom
Afloat16:perf/viewer-summary-record-allocation

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Description

Listing saved review sessions scans every JSONL record to build each summary. readJSONLLines uses bufio.Reader.ReadBytes, which returns an independently allocated record, but peekSession copies 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

  • Refactoring (no functional changes)

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 ListSessions path 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):

Response content per record Before B/op After B/op Before allocs/op After allocs/op
1 KiB 217,237 143,243 214 147
64 KiB 13,711,130 8,992,284 346 279
256 KiB 51,467,546 34,165,786 602 535

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_on for the test suite. The required ocr review --audience agent --background "..." command was attempted, but could not start because no LLM endpoint is configured in the environment.

Checklist

  • The change follows the project's coding style.
  • Tests cover record ownership and real session summary output.
  • New and existing unit tests pass locally.
  • I have signed the CLA.

AI/LLM disclosure: OpenAI ChatGPT (GPT-6 Astra Pro).

@CLAassistant

CLAassistant commented Nov 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

Comment thread internal/viewer/store.go Resolved
Comment thread internal/viewer/store.go Resolved

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit a74bcbb into alibaba:main Nov 19, 2026
13 checks passed
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.

3 participants