Skip to content

perf(net,mux): a container export stops paying per frame for a read that ended - #9235

Merged
kixelated merged 1 commit into
mainfrom
fix/ordered-end-idle
Nov 20, 2026
Merged

kixelated merged 1 commit into
mainfrom
fix/ordered-end-idle

Conversation

@kixelated

@kixelated kixelated commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Nightly's Rust shared bench targets failed in benchmark-report on run 44767045952 with 19 confirmed regressions, all in moq-mux's export bench: container-export/* +86 to 213%, video-reorder/* +83 to 106%, annexb-export-* +77 to 114%.

Bisected locally (container-export/flv/16x64): 5.0 ms at moq-dev/moq#9219, 16.6 ms at moq-dev/moq#9196, its child. A profile put the time in two reads the container consumer makes on every event, which costs O(tracks x frames) full reads per export:

  1. poll_read_finish polls the track's Ordered reader each time. Once it ends, Ordered::poll_next_item walks find_gap twice and a group read through the resume layer (Reader::sync, a track::Consumer clone and drop per call) only to answer Ok(None) again. Its idle gate caches only Pending.
  2. Since feat(net)!: the container reader reads through Ordered, which gives holes up by the max delay alone #9196, poll_read_finish calls join on every item, the end included, and join polls the publisher's largest through the resume layer even after joined is set. Nothing reads largest after that except the newest startup, which polls it itself.

Approach

  • Ordered keeps its idle gate armed after a clean end too (Rest::End), answering Ok(None) until something it registered on fires. Only new ranges can move a read past its end; update already disarms the gate, and the read registers on the subscription's preferences so a Control widening wakes it.
  • join takes the largest only until it joins.

Each half alone leaves most of the cost (below). Together, measured with cargo bench -p moq-mux --bench export (3 s measurement):

Case #9219 (before #9196) main This PR Ordered half only Consumer half only
container-export/flv/16x64 5.00 ms 17.86 ms 1.19 ms 7.07 ms 11.26 ms
container-export/mkv/4x16 - - 148 us 262 us 337 us
video-reorder/pyramid/256x256 297 us 669 us 188 us 350 us 498 us
video-reorder/ts/step-back/1024x256 - - 1.77 ms 3.16 ms 4.44 ms

Validation

  • Reproduced the regression locally at a4fa80a74 (5.24 ms) and a759e4cf6 (17.86 ms), then bisected it to feat(net)!: the container reader reads through Ordered, which gives holes up by the max delay alone #9196 as above.
  • Profiled with perf: before, track::Consumer::clone/drop, resume::Reader::sync, learn_end, and poll_drop_probing led; after the Ordered half, the consumer's poll_largest led, which is how the second half was found. Counters (not committed) showed 17,307 cached end answers per flv/16x64 export with none woken, and 17,336 join calls from poll_read_finish before the consumer half.
  • New test an_ended_ordered_read_reopens_when_a_control_widens_it: an ended read answers its end again, and a Control widening its ranges reopens it.
  • just rs test -p moq-net -p moq-mux -p moq-audio --all-features: 6651 passed. cargo bench -p moq-mux --bench export --bench containers -- --test: every case passes its chunk-count assertions.
  • just check passes.

Caused by

  • moq-dev/moq#9196 - moved the container reader onto Ordered, which recomputes its end on every poll, and joined on every item, so each frame read paid two full reads through the resume layer (found by check: Nightly)

Impact

None: no public API or wire change. A caller polling an ended Ordered past its end gets the same Ok(None) without the work.

Alternatives

  • Fix only the consumer (remember the end, join once): leaves every other Ordered caller (moq-audio, libmoq, moq-ffi) paying a full read per poll past the end, and measures 11 ms here with the join fix alone.
  • Cache the end in Ordered against the preferences' range revision instead of the idle gate: a second terminal flag beside the gate the read already keeps.

Follow-ups

The rest of the 2026-11-20 Nightly's Rust bench failures:

  • Relay session benchmarks: the tasks outlived the cell's handles panic of 2026-11-19 was the paired base (4f3ba3317), which predates moq-dev/moq#9098; both sides ran clean on 2026-11-20. That night's 6 relay regressions are new: relay-join-regressions.
  • Rust bench targets' 55-minute timeout: moq-dev/moq#9199 (approved, unmerged) moves gst out of the group.
  • The 2026-11-19 shared regressions stay with shared-bench-regressions.

Models

Size: M
Implementer: Claude, claude-opus-5-5, unknown effort

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 4aaab40

  • Base: origin/main at 9828a20

  • Risk: medium, The changes to consumer joining and ordered-read caching could disrupt group delivery or range reopening for library users, but preserve public APIs and wire formats and are fully undone by a revert.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a1fa27-dd23-7db2-8e94-edc0b9434b42

  • Reviewer: Codex, gpt-6.1-sol, high effort

  • Session: 01a1fa27-f067-7210-8287-db9bf8ed0edb, round 1

  • Score: 9/10, No actionable regressions were found: preference-change wakeups and startup largest-group refresh remain intact, though review was source-only with no builds or tests run.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

…hat ended

An ordered read answers a repeated end from its idle gate until its ranges
change, and the container consumer takes the publisher's largest only until
it joins. Both ran in full on every frame since the container reader moved
to Ordered, tripling the export and video-reorder benches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Approach: The fix is sound. Both halves remove repeated work at its source: the ended Ordered read reuses the idle gate it already keeps instead of adding a second terminal flag, and join stops re-reading a value nothing uses once the join is set.

Reviewed changes

This review covered the single commit, which caches an ended Ordered read and makes the container consumer's join run once.

  • Ordered caches a clean end: The idle gate now carries Rest::{Pending, End}. On Ok(None), the read registers on the subscription's Preferences before it arms the gate. A Control::update writes that same channel for both Inner::Plain and Inner::Resume, so the write wakes the read. Ordered::update already disarms the gate. Any find_gap or inner-read registration from that full read stays on the gate's waiter too, so a gap found later still reopens the read. I checked that nothing else can move a read past its end:
    • Plain reads: A finished track and fully read ranges are sticky by contract. The poll_next_item docs already say later reads return Ok(None) immediately.
    • Resume reads: Resume poll_end ends the track only on a drained copy or a route end. Copy::reopen runs only from update and set_range, and both go through preferences.
  • join runs once: After joined is set, the only reader of largest is the Startup::Newest arm, and it calls poll_largest itself first. track::Subscriber::poll_largest keeps a seen cursor rather than a queue, so leaving it unpolled builds nothing up.
  • New test: an_ended_ordered_read_reopens_when_a_control_widens_it covers the Control wake path. That path is real here, because the registration goes through the gate's own waker rather than Waiter::noop().
  • Quest doc: relay-join-regressions.md adds a follow-up quest and changes no behaviour.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Nightly regression record lists six benchmark regressions and seven suspected PRs. Consumer::join now keeps an established join boundary and stores the publisher's largest group when available. Ordered caches pending and clean-end read results. A preference-range update can reopen an ended read, as checked by a regression test.

Merge Risk: Minimal · up to 4aaab

This change caches repeated end-of-read answers in the ordered track reader and latches the container consumer's join boundary to cut benchmark overhead. No concrete defect was established, and the author reports a test for reopening an ended read. The merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the performance fix (a container export no longer pays per-frame cost for an ended read) and the affected crates (net, mux). It matches the main change: Ordered keeps its idle gate arm…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and relevant to the changeset. It names the regressed benchmarks (container-export, video-reorder, annexb-export) and bisects them to #9196. It explains the two …
Full details: Title check

Explanation

The title names the performance fix (a container export no longer pays per-frame cost for an ended read) and the affected crates (net, mux). It matches the main change: Ordered keeps its idle gate armed after a clean end, and the container consumer joins only once. The title is specific, short, and follows the conventional-commit style, though it omits the join-once half of the change.

Full details: Description check

Explanation

The description is specific and relevant to the changeset. It names the regressed benchmarks (container-export, video-reorder, annexb-export) and bisects them to #9196. It explains the two causes: Ordered recomputes an ended read on every poll, and the container consumer calls join on every item even after joining. It maps these to the changes in consumer.rs (join latches the largest once) and track.rs (Ordered keeps its idle gate armed after a clean end). It also gives benchmark tables, validation steps, and the impact on public APIs, which is none.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: 72645bdd-6bfc-4016-a242-f3f03375946e
Commits

Reviewing files that changed from the base of the PR and between 9828a20 and 4aaab40.

Files selected for processing: 3

  • quest/m0/nightly/relay-join-regressions.md
  • rs/moq-mux/src/container/consumer.rs
  • rs/moq-net/src/model/track.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@kixelated
kixelated added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 6e59ed7 Nov 20, 2026
7 checks passed
@kixelated
kixelated deleted the fix/ordered-end-idle branch November 20, 2026 19:45
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