Skip to content

perf(moq-mux): a container export steps to the next group before scanning every pending one - #8865

Merged
kixelated merged 1 commit into
mainfrom
perf/mux-export-declared-skips
Nov 16, 2026
Merged

kixelated merged 1 commit into
mainfrom
perf/mux-export-declared-skips

Conversation

@kixelated

@kixelated kixelated commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The scheduled Nightly's paired comparison (run 43724172821) confirmed moq-mux/containers regressions between 4fec611 and 505a86f: annexb-export-* +68%, cmaf-export-* +47..54%, and mkv-payloads/payload-1024/* +30%.

Bisecting the bench binaries puts both on moq-dev/moq#8638 (466f2f6 fast, 7d1bee7 slow). The export side is unintended: group starts are now timestamps, so after a group finishes, current += 1 no longer lands on the next group's start. Every group transition took the hole path, which first reaps aborts over every pending group (poll_finished on each), then scans for the newest content, before the "declared skipped or contiguous" check stepped to the next group. With a queued backlog that is O(pending) per group, so O(groups²) per export. A profile of the 7d1bee7 export spent 12% under that reap alone.

Approach

The container consumer checks whether the cursor can step to the next pending group (poll_continues: the run between is declared skipped, or the group's first frame continues the content read) before the reap and the scans. A front group that is reapable (aborted, nothing buffered, no fault) still goes through the reap first, as before. The hole path reuses poll_continues for its own judgement, so the rule lives in one place.

Validation

Bench binaries built at each commit, run alternately on one host (criterion, 1 s warmup, 2 s measurement), the quietest round:

case 4fec611 (before #8638) 505a86f (Nightly) this PR
annexb-export-frames/1tracks-64frames/4096 186 µs 321 µs 228 µs
annexb-export-queued-groups/64/1 184 µs 321 µs 227 µs
annexb-export-queued-groups/64/16 517 µs 664 µs 562 µs
cmaf-export-frames/4tracks-64frames/256 1.02 ms 1.60 ms 1.18 ms

origin/main (527e301) reads the same as 505a86f (319 µs on queued-groups/64/1).

The remaining ~+23% on these micro cases is spread across moq-net's subscriber, not the consumer: with sparse keys, the reader's Delivered record holds a gap between every pair of handed-out groups, so Cursor::forget_past_budget and the miss judge now run on each take (about 5% of the export profile). See Follow-ups.

just check passes (moq-mux's 2121 tests included).

Impact

  • Public API: none.
  • Wire: none.
  • Behaviour: none intended; the consumer steps to a continuing group in the same cases as before, sooner in its loop.

Alternatives

  • Jumping current straight to the next pending group's start when a group finishes: wrong when a group between them is still in flight.
  • Making the reap incremental: still O(pending) per blocked poll, and the transition doesn't need it at all.

Follow-ups

  • mkv-payloads/payload-1024 (+30%) is not addressed here. It is the producer's cost of declaring skips: every append_group records the span since the previous append as a Skip run (TrackState::appended -> skip_groups -> change_drops), about 0.9 µs per group, 13% of that import profile. feat(moq-net)!: address groups by their start #8638 chose declared skips on purpose; a cheaper representation (an append watermark rather than one run per gap) is a moq-net model change.
  • moq-net's reader could count declared skips as covered in Delivered, so an ordered sparse read leaves no gaps for forget_past_budget to walk.

Caused by

  • moq-dev/moq#8638 - keyed groups by their start but kept current += 1 after a finished group, so every transition took the hole path's O(pending) reap and scans (found by check: the Nightly's paired bench comparison).

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: a42c1ac

  • Base: origin/main at 39e1682

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a1e079-f166-7cc3-b3a3-49d1275196dd, round 1

  • Score: 9/10, No actionable regressions were found; the fast path preserves existing continuity checks while avoiding unnecessary pending-group scans, though builds and tests were not run as instructed.

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

  • Findings: none

…ning every pending one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 15, 2026 18:32

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

Reviewed changes

Reviewed the change to the container consumer's read loop that lets the cursor move to a continuing group before it runs the O(pending) reap and scans.

  • Early step to the next group — when the front pending group is past the cursor, is not reapable, and poll_continues holds, the loop sets current to its start, calls note_group_edge, and continues. It no longer reaps every pending group first.
  • poll_continues extracted — the existing "declared skipped or contiguous" rule now lives in one helper, and the hole path reuses it, so its decision is unchanged.
  • GroupBuffer::reapable extracted — the reap predicate (aborted, nothing buffered, no fault) is now a method shared by the fast path's guard and discard.

I checked that the fast path makes the same choice the hole path made. Between the old reap and the old hole check, nothing else could change the front group. The current_end block only applies when front.start <= current, and the reap only removes groups that are reapable, which the fast path excludes for the front. So whenever the old code would have stepped, the new code steps too. Three things differ, and none affect what the reader sees:

  • The early step skips look_all on the front group, but the next poll_read reads those frames anyway.
  • It no longer logs the skipping missing groups debug line for these steps.
  • Aborted groups further back are reaped later, once delivery blocks.

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

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Consumer::poll_event_once now checks whether the first pending group beyond the cursor is reapable and whether continuity allows advancing to it. The missing-sequence path uses the same continuity check. GroupBuffer::reapable requires an aborted transport stream, no buffered frames, and no stored decode fault.

Merge Risk: Minimal · up to a42c1

The change speeds up how the container consumer moves across pending groups and is not intended to change public behavior. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the container consumer in moq-mux now steps to the next pending group before scanning every pending one, which is a performance fix. It matches the raw summary, the PR…
Description check Passed The description explains the problem (benchmark regressions traced to PR #8638), the approach (checking poll_continues before the reap and scans), validation results, impact, alternatives, and follow-…
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.
Full details: Title check

Explanation

The title names the main change: the container consumer in moq-mux now steps to the next pending group before scanning every pending one, which is a performance fix. It matches the raw summary, the PR objectives, and the description. The 'perf(moq-mux):' prefix is a conventional-commit style tag, and the wording is slightly awkward ('a container export steps'), but the meaning is clear.

Full details: Description check

Explanation

The description explains the problem (benchmark regressions traced to PR #8638), the approach (checking poll_continues before the reap and scans), validation results, impact, alternatives, and follow-ups. It relates directly to the changeset in consumer.rs and the stated objectives.

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: e72a5bf0-9c7e-4933-be32-3747b9f78779
Commits

Reviewing files that changed from the base of the PR and between 39e1682 and a42c1ac.

Files selected for processing: 1

  • rs/moq-mux/src/container/consumer.rs

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

@kixelated
kixelated added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit f3ed57e Nov 16, 2026
7 checks passed
@kixelated
kixelated deleted the perf/mux-export-declared-skips branch November 16, 2026 09:56
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