From 4aaab407174ee89093178122489661fc58e19b0e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 10:11:06 -0800 Subject: [PATCH] perf(net,mux): a container export stops paying per frame for a read that 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 --- quest/m0/nightly/relay-join-regressions.md | 30 ++++++++++++ rs/moq-mux/src/container/consumer.rs | 7 +-- rs/moq-net/src/model/track.rs | 57 ++++++++++++++++++++-- 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 quest/m0/nightly/relay-join-regressions.md diff --git a/quest/m0/nightly/relay-join-regressions.md b/quest/m0/nightly/relay-join-regressions.md new file mode 100644 index 0000000000..e7fba628d1 --- /dev/null +++ b/quest/m0/nightly/relay-join-regressions.md @@ -0,0 +1,30 @@ +# [M] The 2026-11-20 relay session regressions are fixed or accepted + +## Goal + +Nightly's Relay session benchmarks pass the paired comparison again: each +regression from 2026-11-20 is fixed, or accepted by the PR that caused it +with a stated reason. + +## Plan + +Found in run [44767045952](https://github.com/moq-dev/moq/actions/runs/44767045952), +`a759e4cf6` against `a4fa80a74`. Six regressions, consistent across all +three rounds, all on `moq-lite-07-wip`: + +- `relay_session_join_broadcasts/*` +12 to 20%, at 1 to 8 relays and 64 or + 1024 broadcasts. +- `relay_session_join_relays/relays=8/publishers=16` +14.8%. +- `relay_session_delivery_paced/relays=1/publishers=16/viewers=256` +26.9%. + +Suspects, the lite-07 route and subscription changes in that range: +[moq-dev/moq#9112](https://github.com/moq-dev/moq/pull/9112), +[moq-dev/moq#9155](https://github.com/moq-dev/moq/pull/9155), +[moq-dev/moq#9174](https://github.com/moq-dev/moq/pull/9174), +[moq-dev/moq#9179](https://github.com/moq-dev/moq/pull/9179), +[moq-dev/moq#9183](https://github.com/moq-dev/moq/pull/9183), +[moq-dev/moq#9202](https://github.com/moq-dev/moq/pull/9202), and +[moq-dev/moq#9219](https://github.com/moq-dev/moq/pull/9219). Bisect with a +paired local run of one `join_broadcasts` cell before changing code. + +Public API: none expected. Wire: none. diff --git a/rs/moq-mux/src/container/consumer.rs b/rs/moq-mux/src/container/consumer.rs index c94e02aec3..5e58720056 100644 --- a/rs/moq-mux/src/container/consumer.rs +++ b/rs/moq-mux/src/container/consumer.rs @@ -1103,10 +1103,11 @@ impl Consumer { // from a group that raced it, and at the latest as the start is decided, before anything is // dropped against it. fn join(&mut self, waiter: &kio::Waiter) { - self.poll_largest(waiter); - if self.joined.is_none() { - self.joined = self.largest; + if self.joined.is_some() { + return; } + self.poll_largest(waiter); + self.joined = self.largest; } // Drop the pending groups `pick` selects without delivering them. A drop must not hide what diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index bb544a5229..2373a9254c 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -11933,8 +11933,19 @@ pub struct Ordered { /// Whether the drop record exists. It holds only what happened after it began, so it /// starts before the first read. started: bool, - /// The read that last parked, answered again until something it parked on fires. - idle: Option>, + /// The read that last parked or ended, answered again until something it registered on + /// fires. + idle: Option>>, +} + +/// The answer an [`Ordered`] read repeats while nothing it registered on fired. +#[derive(Clone, Copy, PartialEq, Eq)] +enum Rest { + /// It parked. + Pending, + /// It ended cleanly, which only new ranges undo: a caller polling past the end, as one + /// reading the groups it holds does, pays nothing for it. + End, } /// What [`Ordered::poll_next_item`] returns next. @@ -12004,12 +12015,28 @@ impl Ordered { /// Every gap is returned before the end, even a clean one. #[cfg_attr(feature = "async", kio::wrapper)] pub fn poll_next_item(&mut self, waiter: &kio::Waiter) -> Poll>> { - if idle::Idle::parked(&self.idle, (), waiter) { + if idle::Idle::parked(&self.idle, Rest::Pending, waiter) { return Poll::Pending; } + if idle::Idle::parked(&self.idle, Rest::End, waiter) { + return Poll::Ready(Ok(None)); + } let mut idle = idle::Idle::start(&mut self.idle, waiter); let polled = self.poll_item(idle.waiter()); - idle.finish(&mut self.idle, (), polled.is_pending()); + let rest = match &polled { + Poll::Pending => Some(Rest::Pending), + Poll::Ready(Ok(None)) => { + // The ranges are what can move past an end, as a widening update does through + // a [`Control`], whose write wakes this registration. + let _ = self + .inner + .preferences() + .poll_ref(idle.waiter(), |_| Poll::<()>::Pending); + Some(Rest::End) + } + Poll::Ready(_) => None, + }; + idle.finish(&mut self.idle, rest.unwrap_or(Rest::Pending), rest.is_some()); polled } @@ -13457,6 +13484,28 @@ mod test { )); } + /// An ended ordered read answers its end again until a [`Control`], which leaves the read + /// itself alone, widens its ranges. + #[test] + fn an_ended_ordered_read_reopens_when_a_control_widens_it() { + let producer = track_producer("test", Info::timed()); + for key in 0..3 { + write_group(&producer, key); + } + let mut ordered = producer.subscribe(replay().with_range(0..1)).ordered(); + let control = ordered.control(); + let noop = kio::Waiter::noop(); + assert!(matches!(ordered.poll_next_group(&noop), Poll::Ready(Ok(Some(group))) if group.start == 0)); + for _ in 0..2 { + assert!(matches!(ordered.poll_next_group(&noop), Poll::Ready(Ok(None)))); + } + control.update(replay().with_range(0..3)).unwrap(); + for key in 1..3 { + assert!(matches!(ordered.poll_next_group(&noop), Poll::Ready(Ok(Some(group))) if group.start == key)); + } + assert!(matches!(ordered.poll_next_group(&noop), Poll::Ready(Ok(None)))); + } + /// A received copy ends an ordered read between two groups only on what its feed proves: /// a hole it may still land waits, and the starts between skipped, as a GROUP's Previous /// Start says, end it.