You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(net,mux): a container export stops paying per frame for a read that ended - #9235
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:
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.
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):
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.
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
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
…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>
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.
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: 4
Check name
Status
Explanation
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Nightly's Rust shared bench targets failed in
benchmark-reporton run 44767045952 with 19 confirmed regressions, all in moq-mux'sexportbench: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:poll_read_finishpolls the track'sOrderedreader each time. Once it ends,Ordered::poll_next_itemwalksfind_gaptwice and a group read through the resume layer (Reader::sync, atrack::Consumerclone and drop per call) only to answerOk(None)again. Its idle gate caches onlyPending.poll_read_finishcallsjoinon every item, the end included, andjoinpolls the publisher's largest through the resume layer even afterjoinedis set. Nothing readslargestafter that except the newest startup, which polls it itself.Approach
Orderedkeeps its idle gate armed after a clean end too (Rest::End), answeringOk(None)until something it registered on fires. Only new ranges can move a read past its end;updatealready disarms the gate, and the read registers on the subscription's preferences so aControlwidening wakes it.jointakes 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):maincontainer-export/flv/16x64container-export/mkv/4x16video-reorder/pyramid/256x256video-reorder/ts/step-back/1024x256Validation
a4fa80a74(5.24 ms) anda759e4cf6(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.perf: before,track::Consumer::clone/drop,resume::Reader::sync,learn_end, andpoll_drop_probingled; after the Ordered half, the consumer'spoll_largestled, which is how the second half was found. Counters (not committed) showed 17,307 cached end answers perflv/16x64export with none woken, and 17,336joincalls frompoll_read_finishbefore the consumer half.an_ended_ordered_read_reopens_when_a_control_widens_it: an ended read answers its end again, and aControlwidening 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 checkpasses.Caused by
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
Orderedpast its end gets the sameOk(None)without the work.Alternatives
Orderedcaller (moq-audio, libmoq, moq-ffi) paying a full read per poll past the end, and measures 11 ms here with the join fix alone.Orderedagainst 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:
tasks outlived the cell's handlespanic 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.gstout of the group.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 reviewafter 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-edc0b9434b42Reviewer: Codex, gpt-6.1-sol, high effort
Session:
01a1fa27-f067-7210-8287-db9bf8ed0edb, round 1Score: 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