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
14 changes: 10 additions & 4 deletions quest/m1/release-perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ noise.
[#5548](https://github.com/moq-dev/moq/pull/5548) needs. An earliest-deadline
atomic cannot prove a replacement driver is registered, and a lock-free
notification primitive is not worth ~8 ns.
- `track_gap_flush` is accepted at O(log gaps + retired entries) per shared
successor, after [#6287](https://github.com/moq-dev/moq/pull/6287) indexed
the gap ledger and retired a shared verdict's gaps with one split. Each
retired entry must be freed exactly once, so the batch is already amortized
optimal; a representation that hides that reclamation would widen scope for
no measured benefit. Sparse arrivals cost O(log gaps) amortized, and at 4096
gaps flush, read, and expiry instructions fell 80 to 95%.

### Release as a baseline

Expand All @@ -74,9 +81,9 @@ usually pays for a feature.

| Bench | release | main | Ratio | Owner |
|---|---|---|---|---|
| `track_gap_flush/4096` | 5.7 us | 551 us | 96x | [Sparse gaps](/quest/m1/release-perf/sparse-gaps.md) |
| `track_gap_flush/512` | 1.8 us | 48 us | 27x | same |
| `track_gap_flush/64` | 1.5 us | 6.2 us | 4.1x | same |
| `track_gap_flush/4096` | 5.7 us | 551 us | 96x | accepted (above) |
| `track_gap_flush/512` | 1.8 us | 48 us | 27x | accepted (above) |
| `track_gap_flush/64` | 1.5 us | 6.2 us | 4.1x | accepted (above) |
| `stats/session-report/1000x10` | 11.0 us | 86.8 us | 7.9x | accepted (above) |
| `track_gc/idle/16384` | 11.6 ns | 73.7 ns | 6.3x | accepted (above) |
| `origin/resume_overlap/sequence/1r_64g_32c` | 93 us | 426 us | 4.6x | fixed in [moq-dev/moq#6292](https://github.com/moq-dev/moq/pull/6292) |
Expand Down Expand Up @@ -110,7 +117,6 @@ outside the worktree to keep the next one.

## Required

- [Sparse gaps](/quest/m1/release-perf/sparse-gaps.md) - an arrival and a gap flush cost O(log gaps), not O(gaps)
- [Re-check](/quest/m1/release-perf/recheck.md) - the screen-only moves are re-measured with instruction counts, and the ones that hold are fixed or accepted
- [JS frames](/quest/m1/release-perf/js-frames.md) - the js/net frame path is no slower than release in a browser, or the gap is accepted

Expand Down
37 changes: 0 additions & 37 deletions quest/m1/release-perf/sparse-gaps.md

This file was deleted.

158 changes: 133 additions & 25 deletions rs/moq-net/benches/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
//! 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_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.
//!
//! `track_gap_flush` forgets every remembered gap in one hand-out, each below an aborted
//! group still cached: the successor they share must be found once, not once per gap.
//!
Expand Down Expand Up @@ -1019,38 +1022,75 @@ fn bench_parked_read(c: &mut Criterion) {
/// opening a gap at the top, and the lowest missing one, closing the gap at the bottom, so
/// the count stays fixed. Swept over the gaps so a per-hand-out cost that grows with them
/// shows up as a slope.
struct Sparse {
_broadcast: broadcast::Producer,
track: track::Producer,
sub: track::Subscriber,
next: u64,
missing: u64,
timed: bool,
}

impl Sparse {
fn new(info: track::Info, gaps: u64) -> Self {
let broadcast = broadcast::Info::default().produce();
let track = broadcast.create_track("bench", info.clone()).unwrap();
let sub = track.subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(3600)));
let mut sparse = Self {
_broadcast: broadcast,
track,
sub,
next: gaps * 2,
missing: 1,
timed: info.timescale.is_some(),
};
for gap in 0..gaps {
sparse.hand_out(gap * 2);
}
// Fill beyond the cache queue's initial power-of-two capacity outside timing.
// Its amortized growth is independent of how many ledger gaps remain open.
if gaps != 0 {
sparse.advance();
}
sparse
}

fn hand_out(&mut self, sequence: u64) {
let timestamp = self.timed.then(|| Timestamp::from_micros(sequence).unwrap());
let mut group = self.track.create_group(moq_net::group::Info { sequence }).unwrap();
group.write_frame(timestamp, Bytes::from_static(b"x")).unwrap();
group.finish().unwrap();
let Poll::Ready(Ok(Some(read))) = self.sub.poll_recv_group(&kio::Waiter::noop()) else {
panic!("the group is cached");
};
black_box(read);
}

// A profiling boundary excludes filling the initial sparse backlog.
#[inline(never)]
fn read_pair(&mut self) {
self.advance();
}

fn advance(&mut self) {
self.hand_out(self.next);
self.hand_out(self.missing);
self.next += 2;
self.missing += 2;
}
}

fn bench_sparse_read(c: &mut Criterion) {
let mut group = c.benchmark_group("track_sparse_read");
group.throughput(Throughput::Elements(2));
for (name, info) in [("untimed", track::Info::default()), ("timed", timed())] {
for gaps in [16u64, 256, 4096] {
group.bench_function(BenchmarkId::new(name, gaps), |b| {
b.iter_custom(|iterations| {
let broadcast = broadcast::Info::default().produce();
let track = broadcast.create_track("bench", info.clone()).unwrap();
let mut sub =
track.subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(3600)));
// Microseconds, so no run lasts long enough to cross the budget.
let timestamp = |sequence: u64| info.timescale.map(|_| Timestamp::from_micros(sequence).unwrap());
let mut hand_out = |sequence: u64| {
let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap();
group
.write_frame(timestamp(sequence), Bytes::from_static(b"x"))
.unwrap();
group.finish().unwrap();
let Poll::Ready(Ok(Some(read))) = sub.poll_recv_group(&kio::Waiter::noop()) else {
panic!("the group is cached");
};
black_box(read);
};
// Every odd sequence is missing until the bottom gap closes.
for gap in 0..gaps {
hand_out(gap * 2);
}
let mut sparse = Sparse::new(info.clone(), gaps);
let start = WallInstant::now();
for iteration in 0..iterations {
hand_out((gaps + iteration) * 2);
hand_out(iteration * 2 + 1);
for _ in 0..iterations {
sparse.read_pair();
}
start.elapsed()
});
Expand All @@ -1060,6 +1100,71 @@ fn bench_sparse_read(c: &mut Criterion) {
group.finish();
}

/// A sparse feed that opens one gap per millisecond, keeping `gaps` within its budget.
struct Expiring {
sparse: Sparse,
pool: cache::Pool,
now: Instant,
}

impl Expiring {
fn new(gaps: u64) -> Self {
let mut sparse = Sparse::new(track::Info::default(), 0);
sparse
.sub
.update(track::Subscription::default().with_max_delay(Duration::from_millis(gaps)))
.unwrap();
let pool = sparse._broadcast.info().pool.clone();
// Supply time ahead of the host clock, so only these steps age the gaps even
// under an instruction profiler. No cache capacity or idle expiry is enabled.
let mut fixture = Self {
sparse,
pool,
now: Instant::now() + Duration::from_secs(3600),
};
for gap in 0..gaps {
fixture.pool.gc(fixture.now, &kio::Waiter::noop());
fixture.sparse.hand_out(gap * 2);
fixture.now += Duration::from_millis(1);
}
fixture.sparse.next = gaps * 2;
// The eviction queue trails arrivals by one entry: warm both capacities.
fixture.step();
fixture.step();
fixture
}

// One new arrival expires one old gap; excludes building the initial ledger.
#[inline(never)]
fn arrive(&mut self) {
self.step();
}

fn step(&mut self) {
self.now += Duration::from_millis(1);
self.pool.gc(self.now, &kio::Waiter::noop());
self.sparse.hand_out(self.sparse.next);
self.sparse.next += 2;
}
}

fn bench_sparse_expire(c: &mut Criterion) {
let mut group = c.benchmark_group("track_sparse_expire");
for gaps in [16u64, 256, 4096] {
group.bench_function(BenchmarkId::from_parameter(gaps), |b| {
b.iter_custom(|iterations| {
let mut expiring = Expiring::new(gaps);
let start = WallInstant::now();
for _ in 0..iterations {
expiring.arrive();
}
start.elapsed()
});
});
}
group.finish();
}

/// A reader remembering `gaps` gaps, each below a handed-out group since aborted but still
/// cached, then a stamped survivor after them all.
struct GapFlush {
Expand Down Expand Up @@ -1100,6 +1205,8 @@ impl GapFlush {
}

/// Hand out a group two hours on, which puts every remembered gap past the budget.
// A profiling boundary excludes publishing the groups and their aborts.
#[inline(never)]
fn flush(&mut self) {
let mut group = self
.track
Expand All @@ -1123,7 +1230,7 @@ impl GapFlush {
fn bench_gap_flush(c: &mut Criterion) {
let mut group = c.benchmark_group("track_gap_flush");
group.sample_size(10);
for gaps in [64u64, 512, 4096] {
for gaps in [16u64, 64, 256, 512, 4096] {
group.throughput(Throughput::Elements(gaps));
group.bench_function(BenchmarkId::from_parameter(gaps), |b| {
b.iter_batched_ref(|| GapFlush::new(gaps), GapFlush::flush, BatchSize::PerIteration);
Expand Down Expand Up @@ -1375,6 +1482,7 @@ criterion_group!(
bench_datagram_subscriber_join,
bench_parked_read,
bench_sparse_read,
bench_sparse_expire,
bench_gap_flush,
bench_wall,
bench_empty_run,
Expand Down
Loading
Loading