Skip to content

[PR] perf: scan native compaction SSE frames in linear time - #6579

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_linear-terminal-sse
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_linear-terminal-sse

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #6578

Problem

The native compaction observer appends each network chunk to an accumulating string, then normalizes and scans the whole unfinished frame again. A response.completed event can include the complete compacted response, so a long data field repeatedly copies and searches its growing prefix on the relay's event loop.

Changes

Scan each newly decoded chunk once. Keep incomplete-line fragments until a line terminator arrives, join each line once, and assemble the event once at its blank line. A single pending-CRLF flag preserves line-ending behavior across chunk boundaries. Existing terminal classification remains the authority for the first complete verdict.

Validation

  • Six new semantic guards cover multi-MiB frames with LF, CRLF and CR; a large invalid frame followed by a valid failure; one-byte Unicode/multiline splits; and an unfinished large event.
  • All six guards pass on the unchanged base as well; this is a performance change with preserved verdicts.
  • 42 targeted tests pass after the change, including existing SSE framing and JSON terminal controls.
  • Root typecheck, full build, unused-export gate, test-import-graph gate and git diff --check pass.
  • Manual benchmark: 8 MiB payload, 32 KiB chunks, one warmup and three measured runs. Baseline median 482.26 ms; corrected median 67.21 ms, approximately 7.18x faster on this machine. Reproduce with node --import tsx scripts/bench-terminal-sse.ts 8 32. The benchmark has no timing assertion in CI.

Base: e1f31ad. Checked previous Afloat16 PRs and fresh all-state terminal/SSE searches. Existing dispatch-completeness and JSON-status fixes retain their coverage. Hosted CI and real-model E2E remain separate merge gates.

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit 37f41c9c85e (Merge Afloat16/2026-11-13_linear-terminal-sse (PR #6579)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6578 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

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.

Native compaction terminal observer repeatedly copies and scans large SSE frames

2 participants