Skip to content

fix(qmux): split records into frames without copying the rest - #6381

Merged
kixelated merged 6 commits into
mainfrom
quest/m1/release-audit/qmux-copy
Oct 24, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m1/release-audit/qmux-copy

Conversation

@kixelated

@kixelated kixelated commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The QMux WebSocket receive loop decodes each record with decodeRecord (js/qmux/src/frame.ts). Its take helper copied both the payload it split off and the rest of the record, at every length-prefixed frame. A record of N frames therefore copied O(N x record size) bytes. A legal 16,380-byte record of empty STREAM frames copied about 60 MB before dispatch. Completes Parse QMux records without copying suffixes.

Approach

  • take returns views (subarray) for both halves, so walking a record copies nothing. Transport parameters split the same way.
  • Payload ownership is explicit at the retention boundary: a STREAM or DATAGRAM payload is copied once (own) where the session keeps it. A view would pin the whole record behind a tiny frame, against flow control that counts only the frame. The no-length forms, which used to hand out a view of the record, are copied too.
  • decodeQMux (one frame per message, draft-00) had a second copy of every frame type. It now calls decodeQMuxOne, which removes about 130 lines.

Measurements

New just js qmux-record-bench, added to the nightly JS group. Each row is µs per record:

record bytes frames main this
1 KiB 256 STREAM 321 192
16 KiB 16 STREAM 34 15
16 KiB 256 STREAM 578 197
16 KiB 4,095 empty STREAM 10,877 2,706
16 KiB 3,276 MAX_DATA 726 705

What remains is per frame: BigInt varints and frame objects. It no longer grows with the record.

Impact

  • Public API and wire: none. decode and decodeRecord keep their signatures and output.
  • Retained STREAM and DATAGRAM payloads are always their own buffers.

Validation

  • New tests in frame.test.ts count the bytes Uint8Array.prototype.slice copies. Decoding 5,460 empty STREAM frames copies 0 bytes (59,612,280 on main), and 400 32-byte payloads copy exactly 12,800. A retained payload does not alias its record, and a truncated length is still refused.
  • bun test in js/qmux: 202 pass.
  • just check: everything passes except one @moq/hang test, the fallback decodes AAC without a native AudioDecoder. It fails on main from a test-order collision introduced today and is fixed in moq-dev/moq#6382.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU

(Written by Claude Opus 5.5)

kixelated and others added 2 commits October 22, 2026 13:38
`take` copied both the payload it split off and the rest of the record,
so decoding a record of N frames copied O(N x record) bytes: one 16 KB
record of empty STREAM frames copied about 60 MB before dispatch.

Split with views, and copy a STREAM or DATAGRAM payload once where the
session retains it, so a tiny frame never pins the record it arrived
in. The single-frame decoder now reuses the record decoder instead of
repeating every frame type.

Adds `just js qmux-record-bench`, run nightly: record size x frames per
record, including empty STREAM and MAX_DATA frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU
@kixelated
kixelated force-pushed the quest/m1/release-audit/qmux-copy branch from 06f61a3 to 64b3625 Compare October 22, 2026 20:41
@kixelated kixelated changed the title Parse QMux records without copying each remaining suffix fix(qmux): split records into frames without copying the rest Oct 22, 2026
@kixelated
kixelated marked this pull request as ready for review October 22, 2026 20:41
@kixelated

Copy link
Copy Markdown
Collaborator Author

Outcome: the quest is complete and its file is deleted. Record decoding is now linear in record size, with no open decisions, so this is ready for review. just check passes apart from the pre-existing @moq/hang libav test-order failure on main, fixed separately in #6382.

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-24T02:57:59.719834Z 597748f 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.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f954b1ef-7e85-4749-b7c3-a16d78d5dda6
Commits

Reviewing files that changed from the base of the PR and between 9abfd65 and 597748f.

Files selected for processing: 7
  • js/justfile
  • js/qmux/bench/record.ts
  • js/qmux/src/frame.test.ts
  • js/qmux/src/frame.ts
  • quest/m1/release-audit/README.md
  • quest/m1/release-audit/qmux-copy.md
  • sh/gh/nightly.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64b362501e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread js/qmux/src/frame.ts Resolved
The legacy webtransport decoder now splits its frame type off with a
view, so its STREAM payload aliased the WebSocket message. Copy it at
the same retention boundary as the record path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 002f16c84f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	js/justfile
#	quest/m1/release-audit/README.md
#	quest/m1/release-audit/qmux-copy.md
#	sh/gh/nightly.sh
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: eb445b9f1f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary:

  • Merged main (eb445b9). Conflicts: js/justfile and sh/gh/nightly.sh now keep both qmux-record-bench and main's new cmaf-bench. quest/m1/release-audit/README.md takes main's child list without the finished qmux-copy.md entry, and qmux-copy.md stays deleted.
  • The P2 legacy-payload thread is resolved: decodeWebTransport copies its STREAM payload with own, fixed in 002f16c.
  • just check and quest check --base origin/main pass locally. CI is green, and Codex found no issues on eb445b9.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 24, 2026
@kixelated
kixelated enabled auto-merge October 24, 2026 02:56
@kixelated
kixelated added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit 2ad4adc Oct 24, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m1/release-audit/qmux-copy branch October 24, 2026 05:09
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