Skip to content

feat(ts): time a frame split across reads in the bench - #42

Merged
kixelated merged 3 commits into
mainfrom
quest/m2/ts-bench-error-path
Oct 25, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m2/ts-bench-error-path

Conversation

@kixelated

@kixelated kixelated commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Every just ts bench workload decodes a complete buffer, so no error path is priced. #15 left "? returns the incoming Err" undone for that reason.

Approach

  • bench.rs op 7 (decode_split): the video frame headers arrive 3 bytes at a time. Each read decodes every header it completes; a header cut by a read comes up Short through ? and is decoded again from its start on the next read. Output adds the count of short decodes, so every route must retry exactly as often as native Rust.
  • 3-byte reads are shorter than any header (4-6 B), so every header retries at least once.
  • workloads.ts adds frames/video/lite-06/3B-reads and lite-07/3B-reads, 60 items each, so a row lines up with the whole-buffer frames/video decode.
  • Hand-written (moq.ts): a Reader over the bytes so far, drained with tryDecode. This is the subscriber's sync path. A stream-fed Reader would also price a promise for each read.

Numbers

ns per frame header, the median of 15 rounds. Run 2 is an A/B run with --route reuse=: the same translation, edited by hand so every identity ? returns the incoming Err object (return x in place of return rt.Err(x.error), at 10 files' sites). Host: Ryzen 9 5900XT, 32 threads, shared. Load average was 25 at the start and 12 at the end. A/A noise at the median workload: Node 1.8%, Bun 5.0%, Chrome 2.9%.

decode engine native wasm hand-written translated A/A reuse
frames/video/lite-07 Node 4.71 17.8 149 239 243 239
frames/video/lite-07/3B-reads Node 8.77 42.1 826 566 550 531
frames/video/lite-06/3B-reads Node 6.13 57.1 975 627 599 580
frames/video/lite-07 Bun 4.71 17.8 203 334 328 370
frames/video/lite-07/3B-reads Bun 8.77 44.1 1470 715 805 719
frames/video/lite-06/3B-reads Bun 6.13 57.7 1660 816 775 747
frames/video/lite-07 Chrome 4.71 20.4 126 218 214 212
frames/video/lite-07/3B-reads Chrome 8.77 44.4 564 469 456 444
frames/video/lite-06/3B-reads Chrome 6.13 57.6 596 496 501 526
  • Splitting costs the translation about 2.3x per header. moq's hand-written path costs 4.5-7x, because its Short is a thrown value. On this path the translation is 0.5-0.8x hand-written.
  • ? reusing the incoming Err makes a difference of -9% to +6%. The A/A differences on the same rows run from -5% to +13%. Node is the only hint: 6-8% faster on both rows, against A/A's 3-5%. Bun and Chrome are within noise. That is too little to justify the change on a path a real stream rarely takes.

Impact

  • Public API: none. The bench and the codec fixture only. The bench.ts snapshot gains decodeSplit and frameHeader.

Alternatives

  • Price the hand-written route through a ReadableStream with await decode: this adds a promise per read, which is not the error path.
  • Use 1-byte reads: this retries 4-5 times per header, a rate a QUIC stream never shows. 3 bytes keeps it to 1-2 retries.
  • Add audio headers or more read sizes: these give the same error path for more bench time.

Follow-ups

  • None. The ? result above does not justify the optimization; rerun this A/B if the error path ever matters more.

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

(written by Opus 5.5)

kixelated and others added 2 commits October 24, 2026 22:24
Adds a decode of the video frame headers as they arrive 3 bytes at a
time, so every header comes up Short at least once and is decoded again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Error-path workload in the TS benchmark feat(ts): time a frame split across reads in the bench Oct 25, 2026
@kixelated
kixelated marked this pull request as ready for review October 25, 2026 05:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T14:42:20.299813Z 7a4ffc4 New commits
🔒 Security Review ✅ Completed 2026-10-25T14:42:59.529219Z 7a4ffc4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review by review (OpenAI)

Reviewed commit: 3fed326

No actionable bugs found. The benchmark-only direction is sound: retries preserve the incomplete header's start, commit counters only after successful decoding, and include short-decode counts in the existing cross-route output comparison. Two fixed 3-byte workloads exercise both wire formats without unnecessary production complexity.

This agrees with the independent exact-head summary: #42 (comment). Static inspection only; I did not run tests or benchmarks or reproduce reported performance figures.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merging. Since the review, the only change is a merge of origin/main (#36 MIR spike, #41 exporter spike), with no conflicts and no snapshot change.

  • Decisions, accepted by the maintainer: keep the hand-written route's Reader per read, keep 3-byte reads on video at lite-06 and lite-07, and don't make ? reuse the incoming Err (within noise in Bun and Chrome, at most a few percent in Node).
  • Checks: just check and just test passed locally after the merge, quest check --base origin/main is clean, and CI passed on 7a4ffc4.

(written by Opus 5.5)

@kixelated
kixelated merged commit fc2bcf0 into main Oct 25, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-bench-error-path branch October 27, 2026 20:32
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.

1 participant