Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quest/m0/nightly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Public API: none. Wire: none.

## Required

- [The paired bench baseline builds](/quest/m0/nightly/bench-baseline-build.md) - the next scheduled Nightly's paired bench jobs build their baseline and compare, or the baseline moves outside the checkout
- [The browser backend baseline completes on IETF22](/quest/m0/nightly/browser-baseline.md) - the WASM and UniFFI backend baseline completes every supported transport case without an internal error
35 changes: 35 additions & 0 deletions quest/m0/nightly/bench-baseline-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# [XS] The paired bench baseline builds

## Goal

The scheduled Nightly's paired bench jobs build their baseline and get to the
comparison. Check with `gh run list --workflow nightly.yml --event schedule`
and the "Rust bench targets" step of the newest run (the other paired jobs,
such as "io_uring benchmarks", share the cause). Once a scheduled run gets past
the base build, delete this quest.

## Plan

Decided 2026-11-01 (maintainer, `/quest-plan`): a wait-and-check quest that
stays ready, since #7245 likely fixed it already and only the next scheduled
run can tell.

Scheduled run
[41204380716](https://github.com/moq-dev/moq/actions/runs/41204380716)
(2026-10-31) failed every paired bench job before comparing: `bench/run.sh`
checks the baseline out to `$RUN/base`, under `target/bench/nightly/` inside
the main checkout, and Cargo could not merge that checkout's
`.cargo/config.toml` `build-ffi` alias with the current one ("failed to merge
key `build-ffi`").

That run's head already had
[moq-dev/moq#7245](https://github.com/moq-dev/moq/pull/7245), which makes the
aliases strings, so a nested checkout's alias overrides instead of merging.
Its baseline (`previous-nightly`) predated #7245 and still had the list form.
The next scheduled run's baseline includes #7245, so it should build.

If it still fails on the merge, build the baseline outside the checkout (a
`git worktree` beside the repository instead of under `target/`), so no
enclosing `.cargo/config.toml` applies.

Found by [moq-dev/moq#7253](https://github.com/moq-dev/moq/pull/7253).
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- [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
- [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - A/A and deliberately slowed Nightly runs set the paired comparison's threshold, so its regression alerts can be trusted
Expand Down
32 changes: 0 additions & 32 deletions quest/m1/idle-poll-exit.md

This file was deleted.

1 change: 1 addition & 0 deletions quest/m2/perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ revisions on the same host and worker count, and profiles with
- [io_uring buffer pool memory](/quest/m2/perf/uring-pool-memory.md) - measure reserved versus resident pool memory before any shrink policy
- [An idle export poll is cheap](/quest/m2/perf/export-idle-poll.md) - an export poll nothing woke skips the track fill and catalog work it repeats today
- [Mesh session cost](/quest/m2/perf/mesh-session-cost.md) - moq-net's per-session announce, route sync, and scope work drops, swept over sessions and announces
- [Adapter reads reuse their waker](/quest/m2/perf/adapter-waker-alloc.md) - a measured verdict on the per-read waker allocation moq-tokio and moq-uring reads pay since #7042, fixed if real
- [Lite request allocations](/quest/m2/perf/lite-request-allocs.md) - `Path::concat` allocates once and the lite request handler keeps one track-name copy
- [Coverage before START](/quest/m2/perf/covered-before-start.md) - the lite-07 publisher's coverage check costs O(1) per wake before SUBSCRIBE_START
- [io_uring demux churn](/quest/m2/perf/uring-demux-churn.md) - the demux snapshots stats and builds its fed list once per completion, not per datagram
Expand Down
36 changes: 36 additions & 0 deletions quest/m2/perf/adapter-waker-alloc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# [S] Adapter reads reuse their waker

## Goal

A measured verdict on what a parking read costs in the production adapters
(moq-tokio, moq-uring) since
[moq-dev/moq#7042](https://github.com/moq-dev/moq/pull/7042), and a fix if
the cost is real: a stream read that has to wait stops allocating a fresh
shared waker each time.

## Plan

Decided 2026-11-01 (maintainer, `/quest-plan`): measure before fixing, since
no bench has shown the cost yet.

Since #7042, transport polls take a `kio::Waiter` through `&self`, and every
`kio::wait` future (`rs/kio/src/waiter.rs`) holds a waiter of its own. The
moq-net coding layer (`rs/moq-net/src/coding/reader.rs`, `writer.rs`) wraps
each decode or flush in one, so a read that parks allocates the waiter's
shared `Arc<Waker>` every time, where a per-stream `kio::Park` used to reuse
one.

[moq-dev/moq#7262](https://github.com/moq-dev/moq/pull/7262) fixed the
in-memory transport's version (it registered on the session close per read).
The memory-transport benches rarely park, so they cannot see the adapters'
cost.

Measure first: user-space instruction counts and allocations, pinned to one
core, on moq-uring's `session_lite` bench (`just rs bench-session`) and, for
moq-tokio, which has no crate-level session bench, the relay's
`rs/moq-relay/benches/session.rs` or `just bench BASE`. Measure a revision
before #7042 next to main. A measured no-win deletes this quest.

If it is real, let a stream keep one waiter (or `kio::Park`) across reads
again, for example in `coding::Reader`, instead of one per `kio::wait`
future.
9 changes: 9 additions & 0 deletions quest/m2/perf/mesh-session-cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ cost is production code). Cache `OriginScope::relative`'s patterns first;
benchmark before changing the rest.

Public API: none expected.

Decided 2026-11-01 (maintainer, `/quest-plan`): the per-reader cost of a
delivered group belongs here, beside the rest of the per-session cost.
Measured by [moq-dev/moq#7263](https://github.com/moq-dev/moq/pull/7263):
a track read that does get a group still costs about 12k to 26k user-space
instructions per reader per group (1 to 16 readers per track). Part of it is
copying the large `group::Consumer` value, inside
`Poll<Result<Option<group::Consumer>>>`, through each layer that returns it;
consider boxing parts of `group::Consumer`, and measure it on the same read.
78 changes: 76 additions & 2 deletions rs/moq-net/benches/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
//! `track_sparse_read` hands out groups from a feed with every other sequence missing,
//! holding a fixed number of gaps the reader still remembers: each hand-out must cost the
//! same however many gaps it holds, so a walk over them shows up as a slope.
//! `track_sparse_poll` repeats a parked read without changing the feed, so revisiting
//! deferred gaps on an otherwise unchanged poll shows up independently of delivery.
//! `track_sparse_poll` repeats a parked read over a feed holding deferred gaps, without
//! changing it: the repeat parks again without walking, so a slope over the gaps means a
//! repeated read revisits them again.
//!
//! `track_idle_poll` repeats every parked read over readers sharing one track, in arrival
//! and sequence order, with nothing new: a repeated read parks again without walking the
Comment thread
kixelated marked this conversation as resolved.
Resolved
//! read path, so each costs a small constant, and a slope over the readers, or a jump in
//! that constant, means the early exit stopped applying.
//!
//! `track_sparse_expire` opens one new gap while one old gap expires, so a full expiry
//! rescan on each arrival shows up as a slope over the gaps still within budget.
Expand Down Expand Up @@ -1361,6 +1367,73 @@ fn bench_sparse_poll(c: &mut Criterion) {
group.finish();
}

/// Readers parked on one track with nothing new, each having taken the one cached group.
struct Idle {
_broadcast: broadcast::Producer,
_track: track::Producer,
_open: group::Producer,
recv: Vec<track::Subscriber>,
next: Vec<track::Ordered>,
waiter: kio::Waiter,
}

impl Idle {
fn new(readers: usize, ordered: bool) -> Self {
let broadcast = broadcast::Info::default().produce();
let track = broadcast.create_track("bench", timed()).unwrap();
let mut open = track.append_group().unwrap();
open.write_frame(Timestamp::ZERO, Bytes::from_static(b"x")).unwrap();
let waiter = kio::Waiter::noop();
let (mut recv, mut next) = (Vec::new(), Vec::new());
for _ in 0..readers {
let reader = track.subscribe(track::Subscription::default().with_max_delay(AGED_BUDGET));
if ordered {
let mut reader = reader.ordered();
assert!(matches!(reader.poll_next_group(&waiter), Poll::Ready(Ok(Some(_)))));
next.push(reader);
} else {
let mut reader = reader;
assert!(matches!(reader.poll_recv_group(&waiter), Poll::Ready(Ok(Some(_)))));
recv.push(reader);
}
}
let mut idle = Self {
_broadcast: broadcast,
_track: track,
_open: open,
recv,
next,
waiter,
};
// The first park walks the read path; only the repeats are measured.
idle.poll();
idle
}

fn poll(&mut self) {
for reader in &mut self.recv {
assert!(black_box(reader.poll_recv_group(&self.waiter)).is_pending());
}
for reader in &mut self.next {
assert!(black_box(reader.poll_next_group(&self.waiter)).is_pending());
}
}
}

fn bench_idle_poll(c: &mut Criterion) {
let mut group = c.benchmark_group("track_idle_poll");
for (name, ordered) in [("recv", false), ("next", true)] {
for readers in FANOUT {
group.throughput(Throughput::Elements(readers as u64));
group.bench_function(BenchmarkId::new(name, readers), |b| {
let mut idle = Idle::new(readers, ordered);
b.iter(|| idle.poll());
});
}
}
group.finish();
}

/// A sparse feed that opens one gap per millisecond, keeping `gaps` within its budget.
struct Expiring {
sparse: Sparse,
Expand Down Expand Up @@ -2026,6 +2099,7 @@ criterion_group!(
bench_parked_read,
bench_sparse_read,
bench_sparse_poll,
bench_idle_poll,
bench_sparse_expire,
bench_gap_flush,
bench_wall,
Expand Down
63 changes: 60 additions & 3 deletions rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(super) use demand::Preferences;
use demand::Subscriptions;

mod fill;
mod idle;
mod miss;
pub use fill::Fill;
use fill::FillState;
Expand Down Expand Up @@ -6164,6 +6165,9 @@ struct Cursor {
drops: Option<Box<DropCursor>>,
/// What this cursor misses and asks fills for, once it first reads.
misses: Option<Box<miss::Misses>>,
/// The group read that last parked, answered again without the walk until something
/// it parked on fires, once it first parks.
idle: Option<Box<idle::Idle>>,
}

/// A group a cursor found but has not moved past; see [`Cursor::take`].
Expand Down Expand Up @@ -6378,6 +6382,7 @@ impl Cursor {
skipped: Skipped::default(),
drops: None,
misses: None,
idle: None,
}
}

Expand Down Expand Up @@ -6428,6 +6433,8 @@ impl Cursor {
/// Resolve [`Self::servable`] again once the window or cap moved, and publish it to the
/// groups already handed out. Costs the ranges, never the cache.
fn update_servable(&mut self) {
// A moved window or cap notifies nothing this cursor parked on.
idle::Idle::disarm(&mut self.idle);
let runs = Servable::new(self.filter.window.runs(0));
let (revision, cap) = (self.filter.resolved, self.end_sequence);
self.servable = runs.below(cap);
Expand Down Expand Up @@ -6676,6 +6683,11 @@ impl Cursor {
})
}

/// Whether a group read in `walk` order would park again at once; see [`idle`].
fn parked(&self, walk: idle::Walk, waiter: &kio::Waiter) -> bool {
idle::Idle::parked(&self.idle, walk, waiter)
}

/// Take the groups skipped since the last call, for the owner to meter.
fn take_stale(&mut self) -> stats::Content {
std::mem::take(&mut self.stale)
Expand Down Expand Up @@ -6884,10 +6896,17 @@ impl Cursor {
/// Find the next group in arrival order, or in sequence order for `ordered`, without
/// moving past it.
fn poll_peek(&mut self, ordered: bool, taken: &Delivered, waiter: &kio::Waiter) -> Poll<Result<Option<Peeked>>> {
match ordered {
true => self.poll_peek_next(taken, waiter),
false => self.poll_peek_recv(taken, waiter),
let walk = idle::Walk::new(ordered);
if self.parked(walk, waiter) {
return Poll::Pending;
}
let mut idle = idle::Idle::start(&mut self.idle, waiter);
let polled = match ordered {
true => self.poll_peek_next(taken, idle.waiter()),
false => self.poll_peek_recv(taken, idle.waiter()),
};
idle.finish(&mut self.idle, walk, polled.is_pending());
polled
}

/// Move past the group `peeked` found and hand it out: the exact group, even if its
Expand Down Expand Up @@ -7051,6 +7070,7 @@ impl Cursor {
if next == self.next_sequence {
return;
}
idle::Idle::disarm(&mut self.idle);
self.next_sequence = next;
// A group delivered on another copy is not a stale skip on this one.
if !self.seek_pending.is_empty() {
Expand Down Expand Up @@ -7408,6 +7428,15 @@ impl Subscriber {
/// The next group in arrival order, or in sequence order for `ordered`, skipping any
/// already handed out.
fn poll_group(&mut self, ordered: bool, waiter: &kio::Waiter) -> Poll<Result<Option<group::Consumer>>> {
// Ahead of the meter: a read that parks again counts only what a peek skipped.
if let Inner::Plain(cursor) = &self.inner
&& cursor.parked(idle::Walk::new(ordered), waiter)
{
if cursor.stale != stats::Content::default() && self.stats.is_tagged() {
self.count_stale(&self.stats.meter());
}
return Poll::Pending;
}
match self.poll_peek_group(ordered, waiter) {
Poll::Ready(Ok(Some(reserved))) => Poll::Ready(self.take(reserved).map(Some)),
res => {
Expand Down Expand Up @@ -8955,6 +8984,34 @@ mod test {
}
}

/// A read that found nothing parks again at once until something it parked on fires,
/// but parks anew for another task, which the next group then wakes instead.
#[test]
fn an_idle_read_parks_for_the_task_polling_it() {
for ordered in [false, true] {
let producer = track_producer("test", Info::default());
let mut first = framed(&producer, 0, 1);
first.finish().unwrap();
let mut reader = producer.subscribe(replay());
let mut read = |waiter: &kio::Waiter| match ordered {
true => reader.poll_group(true, waiter),
false => reader.poll_group(false, waiter),
};
let (flag, waiter) = Flag::waiter();
assert!(matches!(read(&waiter), Poll::Ready(Ok(Some(_)))));
assert!(read(&waiter).is_pending());
assert!(read(&waiter).is_pending(), "nothing fired, so it parks again");
assert!(!flag.take());

let (other, moved) = Flag::waiter();
assert!(read(&moved).is_pending());
let mut next = framed(&producer, 1, 1);
next.finish().unwrap();
assert!(other.take(), "the next group wakes the task that polled last");
assert!(matches!(read(&moved), Poll::Ready(Ok(Some(_)))));
}
}

/// Write group `sequence` with `frames` frames, left open.
fn framed(producer: &Producer, sequence: u64, frames: usize) -> group::Producer {
let mut group = producer.create_group(group::Info { sequence }).unwrap();
Expand Down
Loading