From 01dc0ff0df7bc34dcb684e48fdaa007936b3e55d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 03:04:30 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m0/ci/quic-padding.md Quest-Claim: 626c3cda0beab522 From aeff48a547a6f408c491be1e5b637b07cc0644c0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 09:37:04 -0700 Subject: [PATCH 2/2] perf(moq-quic): decode a PADDING run as one frame frame::Iter yielded one Frame::Padding per padding byte, so every padded packet cost about a thousand iterator steps. Consume the run in one step. QMux draft-00 still counts each PADDING byte as a frame, so its one-frame-per-message rule is unchanged. Co-Authored-By: Claude Opus 5.5 --- quest/m0/ci/README.md | 1 - quest/m0/ci/quic-padding.md | 16 ------ rs/moq-quic/benches/wire.rs | 74 +++++++++++++------------ rs/moq-quic/src/connection/mux/mod.rs | 6 +- rs/moq-quic/src/connection/mux/tests.rs | 12 ++++ rs/moq-quic/src/frame.rs | 16 +++++- 6 files changed, 72 insertions(+), 53 deletions(-) delete mode 100644 quest/m0/ci/quic-padding.md diff --git a/quest/m0/ci/README.md b/quest/m0/ci/README.md index 700b5b7d160..b323c6ebf50 100644 --- a/quest/m0/ci/README.md +++ b/quest/m0/ci/README.md @@ -135,6 +135,5 @@ The historical samples locate candidates; they are not controlled benchmarks. - [Fewer BTreeMap instantiations](/quest/m0/ci/btree-keys.md) - moq-net shares BTreeMap key and value types, kept only if its CPU time drops - [Halve the slowest tests' CPU](/quest/m0/ci/slow-tests.md) - the slowest 1% of tests take under half their 289 CPU-seconds, with coverage kept - [Recovery clips once](/quest/m0/ci/recovery-clips.md) - `recovery_test`'s FFmpeg clips encode once per run, not once per process -- [Padding runs](/quest/m0/ci/quic-padding.md) - moq-quic parses a PADDING run as one frame, keeping the padding stats' meaning - [tracing-test filter](/quest/m0/ci/tracing-filter.md) - moq-tokio's tests stop forcing every crate to format at TRACE - [Stats oversize](/quest/m0/ci/stats-oversize.md) - moq-stats refuses an oversized plain snapshot before parsing it back diff --git a/quest/m0/ci/quic-padding.md b/quest/m0/ci/quic-padding.md deleted file mode 100644 index 139bd33fd2d..00000000000 --- a/quest/m0/ci/quic-padding.md +++ /dev/null @@ -1,16 +0,0 @@ -# [S] moq-quic collapses padding runs - -## Goal - -moq-quic's frame iterator yields one frame for a run of PADDING bytes instead -of one per byte, cutting the roughly 30% of debug-build handshake CPU it -costs today, and the padding stats still count what they mean to count. - -## Plan - -Found by [moq-dev/moq#6987](https://github.com/moq-dev/moq/pull/6987)'s -profile of the slowest tests. First check what the padding stats should -count (bytes or frames) and keep that meaning. The iterator parses -peer-sent packets, so a run is consumed in one step with no per-byte work. - -Public API: none expected; report any change to the stats. diff --git a/rs/moq-quic/benches/wire.rs b/rs/moq-quic/benches/wire.rs index 2107fbeb983..f9a165dc6dc 100644 --- a/rs/moq-quic/benches/wire.rs +++ b/rs/moq-quic/benches/wire.rs @@ -119,48 +119,54 @@ fn bench_encode(c: &mut Criterion) { } /// Packet and frame decode: the server ingests forged packets of DATAGRAM frames, frames per -/// packet against packets. Only the ingest is timed. +/// packet against packets. `padded` is one small DATAGRAM frame with PADDING filling the rest of +/// the packet, as a padded Initial or MTU probe arrives. Only the ingest is timed. fn bench_decode(c: &mut Criterion) { let mut group = c.benchmark_group("wire_decode"); + let mut shapes = Vec::new(); for frames in [1, 16] { + let data = datagram(frames); + let mut body = BytesMut::new(); + for _ in 0..frames { + datagram_frame(&mut body, &data); + } + shapes.push((format!("frames_{frames}"), frames, body)); + } + let mut padded = BytesMut::new(); + datagram_frame(&mut padded, &payload(1)); + padded.resize(ROOM, 0); + shapes.push(("padded".to_string(), 1, padded)); + for (shape, frames, body) in shapes { for packets in [64, 1024] { let mut state = None; group.throughput(Throughput::Elements(packets as u64)); - group.bench_function( - BenchmarkId::new(format!("frames_{frames}"), format!("packets_{packets}")), - |b| { - let (pair, forge, _) = state.get_or_insert_with(quiet); - let data = datagram(frames); - let mut body = BytesMut::new(); - for _ in 0..frames { - datagram_frame(&mut body, &data); - } - b.iter_custom(|iters| { - let mut busy = Duration::ZERO; - for _ in 0..iters { - let forged: Vec<_> = (0..packets).map(|_| forge.packet(&body)).collect(); - let start = ThreadTime::now(); - for packet in forged { - deliver(pair, packet); - } - busy += start.elapsed(); - - let conn = pair.server.conn(); - let mut received = 0; - while conn.datagrams().recv().is_some() { - received += 1; - } - assert_eq!(received, packets * frames, "server dropped datagrams"); + group.bench_function(BenchmarkId::new(&shape, format!("packets_{packets}")), |b| { + let (pair, forge, _) = state.get_or_insert_with(quiet); + b.iter_custom(|iters| { + let mut busy = Duration::ZERO; + for _ in 0..iters { + let forged: Vec<_> = (0..packets).map(|_| forge.packet(&body)).collect(); + let start = ThreadTime::now(); + for packet in forged { + deliver(pair, packet); + } + busy += start.elapsed(); - // Send the ACKs, which no forged packet acknowledges back. - let empty = conn.datagrams().send_buffer_space(); - flush(pair, empty); - tick(pair); + let conn = pair.server.conn(); + let mut received = 0; + while conn.datagrams().recv().is_some() { + received += 1; } - busy - }); - }, - ); + assert_eq!(received, packets * frames, "server dropped datagrams"); + + // Send the ACKs, which no forged packet acknowledges back. + let empty = conn.datagrams().send_buffer_space(); + flush(pair, empty); + tick(pair); + } + busy + }); + }); } } group.finish(); diff --git a/rs/moq-quic/src/connection/mux/mod.rs b/rs/moq-quic/src/connection/mux/mod.rs index fcfe6b042a3..b6f4b0106e7 100644 --- a/rs/moq-quic/src/connection/mux/mod.rs +++ b/rs/moq-quic/src/connection/mux/mod.rs @@ -539,7 +539,11 @@ impl Connection { break; }; let frame_len = before - payload.len(); - frames += 1; + // A PADDING run decodes as one frame but is a frame per byte on the wire + frames += match frame { + wire::Frame::Quic(frame::Frame::Padding) => frame_len, + _ => 1, + }; if frames > 1 && !self.config.version.uses_records() { return Err(TransportError::FRAME_ENCODING_ERROR( "draft-00 message carries more than one frame", diff --git a/rs/moq-quic/src/connection/mux/tests.rs b/rs/moq-quic/src/connection/mux/tests.rs index 52ba3057bb1..d346f94aca8 100644 --- a/rs/moq-quic/src/connection/mux/tests.rs +++ b/rs/moq-quic/src/connection/mux/tests.rs @@ -275,6 +275,18 @@ fn rejects_empty_records() { ); } +#[test] +fn draft00_counts_each_padding_byte_as_a_frame() { + let mut pair = Pair::new(config(Version::QMux00)); + pair.server.handle_record(Bytes::from_static(&[0x00]), pair.now); + assert!(!pair.server.is_closed()); + pair.server.handle_record(Bytes::from_static(&[0x00, 0x00]), pair.now); + assert_eq!( + transport_error(&mut pair.server).code, + TransportErrorCode::FRAME_ENCODING_ERROR + ); +} + #[test] fn draft00_rejects_qx_ping() { for ty in [0x348c67529ef8c7bd_u64, 0x348c67529ef8c7be] { diff --git a/rs/moq-quic/src/frame.rs b/rs/moq-quic/src/frame.rs index 1b5d1e0a299..21e307c4a9a 100644 --- a/rs/moq-quic/src/frame.rs +++ b/rs/moq-quic/src/frame.rs @@ -573,7 +573,12 @@ impl Iter { let ty = self.bytes.get::()?; self.last_ty = Some(ty); Ok(match ty { - FrameType::PADDING => Frame::Padding, + FrameType::PADDING => { + // Each zero byte is its own PADDING frame, so yield the whole run as one + let run = self.bytes.iter().position(|&b| b != 0).unwrap_or(self.bytes.len()); + self.bytes.advance(run); + Frame::Padding + } FrameType::RESET_STREAM => Frame::ResetStream(ResetStream { id: self.bytes.get()?, error_code: self.bytes.get()?, @@ -985,6 +990,15 @@ mod test { .unwrap() } + #[test] + fn padding_runs_decode_as_one_frame() { + let mut iter = Iter::new(Bytes::from_static(&[0, 0, 0, 0x01, 0, 0])).unwrap(); + assert_matches!(iter.next_with_size(), Some((Ok(Frame::Padding), 3))); + assert_matches!(iter.next_with_size(), Some((Ok(Frame::Ping), 1))); + assert_matches!(iter.next_with_size(), Some((Ok(Frame::Padding), 2))); + assert!(iter.next().is_none()); + } + #[test] fn application_close_coding() { for &error_code in APPLICATION_ERROR_CODES {