From 2df16612ba65e2ce71ce7db64afdcdb5376d9146 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 23:49:24 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m0/nightly/bench-regressions.md Quest-Claim: afa08bbd2b1d0b80 From c64ab70ad16f6518352b0e9aa6dbc319d898ae28 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:39:49 -0800 Subject: [PATCH 2/3] perf(audio,mux): skip comfort measurement on the bus, adopt parameter sets in linear time Co-Authored-By: Claude Opus 5.5 --- rs/moq-audio/src/aec.rs | 1 + rs/moq-audio/src/bus.rs | 3 ++ rs/moq-audio/src/playback/mixer.rs | 2 ++ rs/moq-audio/src/playback/sink.rs | 1 + rs/moq-audio/src/ring.rs | 49 ++++++++++++++++++++++++++++-- rs/moq-mux/src/codec/annexb.rs | 17 +++++++---- 6 files changed, 65 insertions(+), 8 deletions(-) diff --git a/rs/moq-audio/src/aec.rs b/rs/moq-audio/src/aec.rs index bb9c2642140..28c7269f236 100644 --- a/rs/moq-audio/src/aec.rs +++ b/rs/moq-audio/src/aec.rs @@ -533,6 +533,7 @@ fn channel(rate: u32) -> (ring::Producer, ring::Consumer) { // is shaped to avoid. pad: false, trim: true, + comfort: false, }, ) } diff --git a/rs/moq-audio/src/bus.rs b/rs/moq-audio/src/bus.rs index 2649640bd7b..6e0ee5dbded 100644 --- a/rs/moq-audio/src/bus.rs +++ b/rs/moq-audio/src/bus.rs @@ -374,6 +374,9 @@ impl Bus { // the target depth, not by letting the ring run dry or full. pad: true, trim: true, + // No writer here declares a silence, so measuring for comfort + // noise would be wasted on every block. + comfort: false, }, ); let port = self.open(input, strip, Queue::Live(cons))?; diff --git a/rs/moq-audio/src/playback/mixer.rs b/rs/moq-audio/src/playback/mixer.rs index 295ee8eabc3..8b66edcadb2 100644 --- a/rs/moq-audio/src/playback/mixer.rs +++ b/rs/moq-audio/src/playback/mixer.rs @@ -486,6 +486,7 @@ mod tests { capacity: Duration::from_secs(1), pad: true, trim: true, + comfort: true, }, ); @@ -818,6 +819,7 @@ mod tests { capacity: Duration::from_millis(200), pad: true, trim: true, + comfort: true, }, ) } diff --git a/rs/moq-audio/src/playback/sink.rs b/rs/moq-audio/src/playback/sink.rs index b46b81766c9..2e01e096fcf 100644 --- a/rs/moq-audio/src/playback/sink.rs +++ b/rs/moq-audio/src/playback/sink.rs @@ -513,6 +513,7 @@ fn channel(input: &Input, rate: u32, bus: Layout) -> (Channel, ring::Consumer) { // pays for emergency silence or trimming. pad: true, trim: true, + comfort: true, }, ); cons.stretch(rate); diff --git a/rs/moq-audio/src/ring.rs b/rs/moq-audio/src/ring.rs index ce324ba4733..9019ad02a69 100644 --- a/rs/moq-audio/src/ring.rs +++ b/rs/moq-audio/src/ring.rs @@ -42,6 +42,10 @@ pub(crate) struct Config { /// Trim back down to the latency once the queue fills three quarters of the /// room above it. pub trim: bool, + /// Measure what plays, so a declared silence fills with comfort noise at + /// its level. Without it a declared silence is plain silence, for a writer + /// that never declares one. + pub comfort: bool, } /// What a [`Producer::push`] did with its input. @@ -157,6 +161,7 @@ pub(crate) fn channel(channels: usize, input_rate: u32, output_rate: u32, config cleared: 0, cushioned: 0, comfort: crate::comfort::Comfort::new(output_rate, channels), + measure: config.comfort, trim: config.trim, skips: 0, trimmed: 0, @@ -495,6 +500,8 @@ pub(crate) struct Consumer { /// Comfort noise already played at the pending resume. cushioned: usize, comfort: crate::comfort::Comfort, + /// Whether the comfort noise measures what plays; unmeasured, it fills plain silence. + measure: bool, /// Trim only after filling three quarters of the current target's headroom. trim: bool, /// Times [`Read::Trimmed`] was returned, ever. @@ -612,7 +619,7 @@ impl Consumer { while done < output.len() { if let Some(stretch) = self.stretch.as_mut().filter(|stretch| stretch.available() > 0) { let frames = stretch.read(&mut output[done..]); - if !self.staged_prime { + if self.measure && !self.staged_prime { self.comfort.played(&output[done..done + frames * channels]); } done += frames * channels; @@ -642,7 +649,9 @@ impl Consumer { debug_assert_eq!(read, frames * channels); let prime = frames.min(self.prime); self.prime -= prime; - self.comfort.played(&output[done + prime * channels..done + read]); + if self.measure { + self.comfort.played(&output[done + prime * channels..done + read]); + } self.position = self.position.wrapping_add(frames); self.consumed = self.consumed.wrapping_add(frames); done += read; @@ -756,6 +765,7 @@ mod tests { capacity, pad: false, trim: false, + comfort: true, }, ); cons.start(); @@ -838,6 +848,7 @@ mod tests { capacity: Duration::from_millis(200), pad: false, trim: true, + comfort: true, }, ); cons.start(); @@ -865,6 +876,7 @@ mod tests { capacity: Duration::from_millis(100), pad: false, trim: false, + comfort: true, }, ); assert_eq!(prod.push(&[0.5; 2 * STEREO]), Push::NotReady); @@ -892,6 +904,7 @@ mod tests { capacity: Duration::from_millis(100), pad: true, trim: true, + comfort: true, }, ); cons.start(); @@ -920,6 +933,7 @@ mod tests { capacity: Duration::from_millis(100), pad: false, trim: true, + comfort: true, }, ); cons.start(); @@ -964,6 +978,7 @@ mod tests { capacity: Duration::from_secs(3), pad: false, trim: false, + comfort: true, }, ); cons.stretch(rate); @@ -1018,6 +1033,7 @@ mod tests { capacity: Duration::from_secs(1), pad: false, trim: false, + comfort: true, }, ); cons.stretch(48_000); @@ -1051,6 +1067,7 @@ mod tests { capacity: Duration::from_secs(1), pad: false, trim: false, + comfort: true, }, ); cons.stretch(48_000); @@ -1079,6 +1096,7 @@ mod tests { capacity: Duration::from_secs(1), pad: true, trim: false, + comfort: true, }, ); cons.stretch(48_000); @@ -1113,6 +1131,7 @@ mod tests { capacity: Duration::from_millis(3050), pad: false, trim: true, + comfort: true, }, ); cons.stretch(48_000); @@ -1200,6 +1219,31 @@ mod tests { assert_eq!(cons.read(&mut out), Read::Underflow { frames: 0 }); } + /// A queue that measures nothing fills a declared silence with plain silence. + #[test] + fn an_unmeasured_declared_silence_is_silent() { + let (mut prod, mut cons) = channel( + STEREO, + 48_000, + 48_000, + Config { + latency: Duration::from_millis(50), + capacity: Duration::from_secs(1), + pad: false, + trim: false, + comfort: false, + }, + ); + cons.start(); + assert_eq!(prod.push(&[0.0002; 4800 * STEREO]), Push::Ok); + let mut out = vec![0.0; (LATENCY + 4800) * STEREO]; + assert_eq!(cons.read(&mut out), Read::Ok); + prod.end(); + let mut out = vec![1.0; 1000 * STEREO]; + assert_eq!(cons.read(&mut out), Read::Comfort { frames: 0 }); + assert!(out.iter().all(|&sample| sample == 0.0)); + } + /// A next utterance pushed while the end's tail still plays waits behind it, /// with comfort noise topping the wait up to one latency. #[test] @@ -1296,6 +1340,7 @@ mod tests { capacity: Duration::from_secs(1), pad: true, trim: false, + comfort: true, }, ); cons.stretch(48_000); diff --git a/rs/moq-mux/src/codec/annexb.rs b/rs/moq-mux/src/codec/annexb.rs index ba3a9e85c72..3b22261b234 100644 --- a/rs/moq-mux/src/codec/annexb.rs +++ b/rs/moq-mux/src/codec/annexb.rs @@ -220,9 +220,16 @@ pub(crate) type ParameterSets = BTreeMap<(u8, u32), Bytes>; /// Adopt the parameter sets of one type that an access unit or init defined: each layer it /// defined any for replaces that layer's retained sets, dropping ids the new configuration no /// longer uses, while every other layer keeps its own. An empty `sets` changes nothing. -pub(crate) fn adopt_parameter_sets(retained: &mut ParameterSets, sets: ParameterSets) { - retained.retain(|(layer, _), _| !sets.keys().any(|(defined, _)| defined == layer)); - retained.extend(sets); +pub(crate) fn adopt_parameter_sets(retained: &mut ParameterSets, mut sets: ParameterSets) { + let defined = layers(&sets); + retained.retain(|&(layer, _), _| defined & 1 << layer == 0); + // Appending to an emptied map moves `sets` in rather than inserting each set. + retained.append(&mut sets); +} + +/// The layers `sets` holds any for, as a bitmask: `nuh_layer_id` has six bits. +fn layers(sets: &ParameterSets) -> u64 { + sets.keys().fold(0, |mask, &(layer, _)| mask | 1 << layer) } /// The NAL syntax an [`InBand`] transform reads. @@ -441,9 +448,7 @@ pub(crate) fn reconcile_keyframe_params( ) -> Result<()> { let mut missing = false; for (retained, seen) in retained.iter_mut().zip(seen.iter_mut()) { - missing |= retained - .keys() - .any(|(layer, _)| !seen.keys().any(|(defined, _)| defined == layer)); + missing |= layers(retained) & !layers(seen) != 0; adopt_parameter_sets(retained, std::mem::take(*seen)); seen.clone_from(retained); } From 450d86f6331a56da8e9515dcfbfc902e7034afb7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:42:39 -0800 Subject: [PATCH 3/3] quest: finish quest/m0/nightly/bench-regressions.md Co-Authored-By: Claude Opus 5.5 --- quest/m0/nightly/README.md | 1 - quest/m0/nightly/bench-regressions.md | 32 --------------------------- 2 files changed, 33 deletions(-) delete mode 100644 quest/m0/nightly/bench-regressions.md diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 3a82a9d0589..6ae867590a4 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -53,5 +53,4 @@ near the paired threshold (re-check if one repeats), a one-off - [Nightly's macOS platform job passes](/quest/m0/nightly/macos.md) - `moq-audio`'s tests compile on macOS again and the websocket version test's timeout is fixed if it recurs - [The qmux startup benchmark's fake peer sends transport parameters](/quest/m0/nightly/qmux-bench-peer.md) - Audio quality's WebSocket startup step stops timing out - [The moq-net session bench completes moq-transport-22 at 16 broadcasts](/quest/m0/nightly/session-bench-handshake.md) - the bench workload stops panicking on a handshake timeout -- [Bisect the moq-audio bus and moq-mux parameter_sets regressions](/quest/m0/nightly/bench-regressions.md) - two real benchmark regressions are explained and fixed or accepted - [Moxygen conformance cells pass again](/quest/m0/nightly/moxygen-conformance.md) - the first-object signal and integer extensions survive, or moxygen's divergence is skipped with an upstream link diff --git a/quest/m0/nightly/bench-regressions.md b/quest/m0/nightly/bench-regressions.md deleted file mode 100644 index 4f66dcbfb98..00000000000 --- a/quest/m0/nightly/bench-regressions.md +++ /dev/null @@ -1,32 +0,0 @@ -# [M] Bisect the moq-audio bus and moq-mux parameter_sets regressions - -## Goal - -Two benchmark regressions Nightly flagged are explained and either fixed or -accepted with a recorded reason: - -- 13 `moq-audio/bus` cases (`bus_minus`, `bus_mixes`, `bus_sources`), +16 to - +29% together, between `fbef872` and `b5805859`. -- `moq-mux/parameter_sets h264-split-pps/distinct`, +14% / +26% / +46% at - n = 16 / 256 / 4096, so the cost grows with n. - -## Plan - -Planned 2026-11-09 (maintainer, /quest-complete from the triage of Nightly -runs [42377867523](https://github.com/moq-dev/moq/actions/runs/42377867523) -(the bus set, in "Rust supplemental benchmarks") and -[42487375545](https://github.com/moq-dev/moq/actions/runs/42487375545) (the -parameter sets, in "Rust shared")). Both look real: the bus cases moved -together, and the parameter_sets cost scales with n, which points at a -per-item cost that grew rather than noise. - -Suspects from the triage, to confirm by bisecting with the paired -comparison (`bench/README.md#paired-comparison`), not by reading: -[moq-dev/moq#8121](https://github.com/moq-dev/moq/pull/8121) (encoders take a -join) and [moq-dev/moq#8010](https://github.com/moq-dev/moq/pull/8010) -(comfort noise) for the bus; [moq-dev/moq#8140](https://github.com/moq-dev/moq/pull/8140) -and [moq-dev/moq#8199](https://github.com/moq-dev/moq/pull/8199) for the -parameter sets. Name the culprit PR under `## Caused by`. A regression that -buys correctness may stay, with the trade recorded in the PR. - -Public API: none expected. Wire: none.