diff --git a/quest/m1/README.md b/quest/m1/README.md index ed83be42ae0..26bf657f386 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -163,7 +163,6 @@ removed). - [Rust releases publish through OIDC](/quest/m1/release-rs-oidc.md) - release-plz publishes with trusted publishing and `CARGO_REGISTRY_TOKEN` is revoked - [kio's clock tests pass under cargo test](/quest/m1/clock-test-process.md) - `paused_runtimes_own_their_anchors` stops depending on being first in its process - [The JS stalled-consumer eviction test ages its groups](/quest/m1/js-cache-age-test.md) - the test drives the clock the cache reads, so it can fail -- [moq-transport-22 FETCH cost](/quest/m1/ietf22-fetch-poll-cost.md) - #7042's +12.8% instructions on draft-22 FETCH is fixed or attributed - [An idle track poll exits cheaply](/quest/m1/idle-poll-exit.md) - a reader's poll on a track with nothing new costs a small constant, not ~3,800 instructions - [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut - [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18 and 22 diff --git a/quest/m1/ietf22-fetch-poll-cost.md b/quest/m1/ietf22-fetch-poll-cost.md deleted file mode 100644 index 6adfd302ed5..00000000000 --- a/quest/m1/ietf22-fetch-poll-cost.md +++ /dev/null @@ -1,34 +0,0 @@ -# [M] moq-transport-22 FETCH costs what it did before the waiter refactor - -## Goal - -A moq-transport-22 FETCH of 256-frame groups costs no more instructions than -it did before [moq-dev/moq#7042](https://github.com/moq-dev/moq/pull/7042), or -the remaining cost is attributed to work the refactor needs and recorded in -its PR. Other versions and group sizes don't regress. - -## Plan - -Found 2026-10-28 by the paired-relay measurements in -[moq-dev/moq#7141](https://github.com/moq-dev/moq/pull/7141): #7042 -(`6eff65506e`, "transport polls take kio waiters through &self") adds +12.8% -instructions on moq-transport-22 FETCH of 256-frame groups (8.02M to 9.04M per -round). The commit before it measures the same as the head. It landed after the -range the 2026-10-28 Nightly compared, so the next paired Nightly may flag it. - -Decided 2026-10-28 (maintainer): m1, not a Nightly blocker. - -- Attribute with instruction counts (`perf stat --no-scale` pinned to one core - type, or callgrind), not wall time: the hosted runners and a busy host are - too noisy for a 13% delta. Give each revision its own `CARGO_TARGET_DIR`. -- Find which poll path the refactor made more expensive on draft 22's FETCH - (per-call waiter registration, extra polls, or a lost fast path), and fix it - at the cause without reverting the `&self` waiter API. -- Sweep the relay session bench's FETCH cases across lite-07, draft 18 and - draft 22, at 4- and 256-frame groups, and record before and after. - -Public API: none. Wire: none. - -## Related - -- [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - owns the gate's threshold if the Nightly flags this first diff --git a/rs/moq-net/src/transport/memory.rs b/rs/moq-net/src/transport/memory.rs index 09ea66b6fcf..d41267eafd6 100644 --- a/rs/moq-net/src/transport/memory.rs +++ b/rs/moq-net/src/transport/memory.rs @@ -427,6 +427,14 @@ enum End { } impl Channel { + /// Whether a read would return now: a queued message or the end. + fn readable(&self) -> Poll<()> { + match !self.messages.is_empty() || self.end.is_some() { + true => Poll::Ready(()), + false => Poll::Pending, + } + } + /// Close with a reset or stop code and drop what is queued. An earlier end stands, /// unless it was a finish the reader has not fully read. fn abort(&mut self, end: End) { @@ -477,17 +485,20 @@ impl poll::SendStream for SendStream { return Poll::Ready(Ok(0)); } - if let Poll::Ready(err) = poll_close(&self.close, waiter) { + // Peek at the close rather than register on it: only a write that parks waits for it. + if let Some(err) = closed(&self.close) { return Poll::Ready(Err(err)); } let buffer = self.buffer; - let mut channel = ready!(self.channel.poll(waiter, |channel| { + let Poll::Ready(mut channel) = self.channel.poll(waiter, |channel| { match channel.end.is_some() || channel.messages.is_empty() || channel.queued < buffer { true => Poll::Ready(()), false => Poll::Pending, } - })); + }) else { + return poll_close(&self.close, waiter).map(Err); + }; if let Some(End::Stop(code)) = channel.end { return Poll::Ready(Err(Error::Stopped(code))); } @@ -591,16 +602,17 @@ impl poll::Chunks for Chunks { return Poll::Ready(Ok(Some(Bytes::new()))); } - // Check the close first, so a message queued before it is still read below. - let closed = poll_close(&self.close, waiter); - let Poll::Ready(mut channel) = self.channel.poll(waiter, |channel| { - match !channel.messages.is_empty() || channel.end.is_some() { - true => Poll::Ready(()), - false => Poll::Pending, + // Only a read that parks registers on the close, so a ready read costs one lock. + let mut channel = match self.channel.poll(waiter, |channel| channel.readable()) { + Poll::Ready(channel) => channel, + Poll::Pending => { + let err = ready!(poll_close(&self.close, waiter)); + // Queued messages drain first, so look again: one may have landed before the close. + match self.channel.poll(waiter, |channel| channel.readable()) { + Poll::Ready(channel) => channel, + Poll::Pending => return Poll::Ready(Err(err)), + } } - }) else { - // Queued messages drain first; only an idle stream fails with the close. - return closed.map(Err); }; let Some(front) = channel.messages.front_mut() else { @@ -968,6 +980,49 @@ mod tests { assert!(closed(ready(b.poll_accept_uni(&noop())).err().unwrap())); } + /// Only a parked read or write waits on the close: one that returns at once leaves no + /// registration behind, as every frame of a session pays for one. + #[test] + fn only_parked_streams_wait_on_the_close() { + let (a, b) = pair(buffer(0)); + let (mut send, mut recv) = uni(&a, &b); + let counted = || { + let count = Arc::new(Count::default()); + (kio::Waiter::new(Waker::from(count.clone())), count) + }; + + let (ready_write, ready_write_count) = counted(); + assert_eq!( + ready(send.poll_write_buf(&ready_write, &mut Bytes::from_static(b"one"))).unwrap(), + 3 + ); + let (ready_read, ready_read_count) = counted(); + let chunk = ready(poll::Chunks::poll_read_chunk(recv.get_mut(), &ready_read, usize::MAX)); + assert_eq!(chunk.unwrap().unwrap(), "one"); + + // The channel is empty, so the read parks; refill it so the write parks too. + let (parked_read, parked_read_count) = counted(); + assert!(poll::Chunks::poll_read_chunk(recv.get_mut(), &parked_read, usize::MAX).is_pending()); + let (mut other, _other_recv) = uni(&a, &b); + ready(write(&mut other, &Bytes::from_static(b"two"))).unwrap(); + let (parked_write, parked_write_count) = counted(); + assert!( + other + .poll_write_buf(&parked_write, &mut Bytes::from_static(b"x")) + .is_pending() + ); + + a.close(4, "bye"); + assert_eq!(ready_write_count.0.load(Ordering::Relaxed), 0); + assert_eq!(ready_read_count.0.load(Ordering::Relaxed), 0); + assert!(parked_read_count.0.load(Ordering::Relaxed) > 0); + assert!(parked_write_count.0.load(Ordering::Relaxed) > 0); + + let closed = |err: Error| matches!(err, Error::Session { code: 4, .. }); + assert!(closed(ready(read(&mut recv, usize::MAX)).unwrap_err())); + assert!(closed(ready(write(&mut other, &Bytes::from_static(b"x"))).unwrap_err())); + } + #[test] fn dropping_a_side_closes() { let (a, b) = pair(Config::default());