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
42 changes: 19 additions & 23 deletions rs/moq-net/benches/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
//! - unique: random single-segment paths and random two-hop chains, where no path
//! is shared and every START pays the two zero base/keep bytes.
//!
//! The hop chains travel only on lite-06; lite-07 names each claim's route instead.
//! The hop chains travel only on lite-06; lite-07 names each claim's route instead, so
//! its streams carry none.
//!
//! The byte counts print once before the timings.
//!
Expand Down Expand Up @@ -109,18 +110,19 @@ fn id(seed: u64) -> u64 {
((z ^ (z >> 31)) & ((1 << 62) - 1)).max(1)
}

/// Start route `n`, with its hop chain only on lite-06: a lite-07 claim names its route
/// instead, and carries a chain only when it was learned over lite-06.
fn start(route: fn(u64) -> (Path, Vec<u64>), n: u64, compress: bool) -> Announced {
let (path, hops) = route(n);
Announced::Start(path, if compress { Vec::new() } else { hops })
}

/// Announce `routes` routes, then replace `churn` of them, oldest first.
fn stream(routes: u64, churn: u64, route: impl Fn(u64) -> (Path, Vec<u64>)) -> Vec<Announced> {
let mut announced: Vec<_> = (0..routes)
.map(|n| {
let (path, hops) = route(n);
Announced::Start(path, hops)
})
.collect();
fn stream(routes: u64, churn: u64, route: fn(u64) -> (Path, Vec<u64>), compress: bool) -> Vec<Announced> {
let mut announced: Vec<_> = (0..routes).map(|n| start(route, n, compress)).collect();
for n in 0..churn {
announced.push(Announced::End(n));
let (path, hops) = route(routes + n);
announced.push(Announced::Start(path, hops));
announced.push(start(route, routes + n, compress));
}
announced
}
Expand Down Expand Up @@ -150,9 +152,8 @@ fn report() {
eprintln!("announce stream bytes (lite-06 literal -> lite-07 compressed):");
for (name, route) in WORKLOADS {
for (routes, churn) in SHAPES {
let announced = stream(routes, churn, route);
let literal = encode_announces(&announced, false).len();
let compressed = encode_announces(&announced, true).len();
let literal = encode_announces(&stream(routes, churn, route, false), false).len();
let compressed = encode_announces(&stream(routes, churn, route, true), true).len();
let starts = routes + churn;
eprintln!(
" {name:>6} routes={routes:>5} churn={churn:>5}: {literal:>8} -> {compressed:>8} bytes, {:.1} -> {:.1} per START ({:+.0}%)",
Expand All @@ -171,17 +172,12 @@ fn bench(c: &mut Criterion) {
let mut group = c.benchmark_group(format!("announce_{name}"));

for routes in LIVE {
// A ring twice the live set, so the route started never collides with one
// still live.
let ring: Vec<_> = (0..2 * routes)
.map(|n| {
let (path, hops) = route(n);
Announced::Start(path, hops)
})
.collect();
group.throughput(Throughput::Elements(2));

for compress in [false, true] {
// A ring twice the live set, so the route started never collides with one
// still live.
let ring: Vec<_> = (0..2 * routes).map(|n| start(route, n, compress)).collect();
let version = if compress { "lite07" } else { "lite06" };
group.bench_function(BenchmarkId::new(format!("churn_{version}"), routes), |b| {
let mut writer = AnnounceWriter::new(compress);
Expand All @@ -201,9 +197,9 @@ fn bench(c: &mut Criterion) {
}

for (routes, churn) in SHAPES {
let announced = stream(routes, churn, route);
group.throughput(Throughput::Elements(announced.len() as u64));
for compress in [false, true] {
let announced = stream(routes, churn, route, compress);
group.throughput(Throughput::Elements(announced.len() as u64));
let version = if compress { "lite07" } else { "lite06" };
let encoded = encode_announces(&announced, compress);
group.bench_with_input(
Expand Down
18 changes: 13 additions & 5 deletions rs/moq-net/benches/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ fn decode() {
];
for (name, shape) in shapes {
let paths: Vec<Path> = (0..1000).map(|i| moq_net::Path::try_from(shape(i)).unwrap()).collect();
let stream: Vec<Announced> = paths
.iter()
.enumerate()
.map(|(i, path)| Announced::Start(path.clone(), vec![0x1111 + i as u64, 0x2222]))
.collect();
for compress in [false, true] {
// Lite-07 names a claim's route in place of its hop chain.
let stream: Vec<Announced> = paths
.iter()
.enumerate()
.map(|(i, path)| {
let hops = if compress {
vec![]
} else {
vec![0x1111 + i as u64, 0x2222]
};
Announced::Start(path.clone(), hops)
})
.collect();
let data = encode_announces(&stream, compress);
let version = if compress { "lite07" } else { "lite06" };
allocs(&format!("decode/announce_{version}/{name}"), 50, 1000, || {
Expand Down
Binary file not shown.
16 changes: 4 additions & 12 deletions rs/moq-net/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ fn hop_chain(ids: impl IntoIterator<Item = u64>) -> Hops {

/// One announcement on an announce stream, resolved: what the application sees.
///
/// The hop chain travels only on lite-06: lite-07 names the claim's route instead, so
/// its writer drops the chain and its reader decodes an empty one.
/// The hop chain is lite-06's, and lite-07's trailing Lite-06 Chain: a lite-07 claim
/// names its route instead, and carries a chain only when it was learned over lite-06.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Announced {
/// ANNOUNCE_START: a route's suffix and wire hop ids, taking the next id.
Expand Down Expand Up @@ -496,13 +496,13 @@ impl AnnounceWriter {
instance: self.version.has_instance().then(|| "a".parse().unwrap()),
epoch: 0,
suffix,
hops: self.chain(hops),
hops: hop_chain(hops.iter().copied()),
cost: Default::default(),
}
}
Announced::Update(id, hops) => lite::AnnounceBroadcast::Update {
id: *id,
hops: self.chain(hops),
hops: hop_chain(hops.iter().copied()),
cost: Default::default(),
},
Announced::End(id) => {
Expand All @@ -513,14 +513,6 @@ impl AnnounceWriter {
msg.encode(&mut Encoder::new(data, self.version.into()), self.version)
.expect("could not encode an announcement");
}

/// The hop chain as this version carries it: none on lite-07.
fn chain(&self, hops: &[u64]) -> Hops {
match self.version.has_routes() {
true => Hops::default(),
false => hop_chain(hops.iter().copied()),
}
}
}

/// Mark `track` as a copy received from a remote publisher, as a subscriber session does, for
Expand Down