bench: add allocation decomposition benchmark for send_to

Measures Box::new+type-erasure (2-160ns) vs full send_to (1.9-7.2us) to
identify the real send latency bottleneck. Finding: allocation is only
1-5% of total cost; the dominant overhead is RwLock address_map lookup
and HybridChannel operations.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
This commit is contained in:
Claude 2026-02-13 10:35:59 +00:00
parent 7425e484a1
commit 83aabc26e1

View file

@ -722,6 +722,66 @@ fn registry_benchmarks(c: &mut Criterion) {
group.finish();
}
// ---------------------------------------------------------------------------
// Allocation decomposition — where does send_to time go?
// ---------------------------------------------------------------------------
fn allocation_benchmarks(c: &mut Criterion) {
let mut group = c.benchmark_group("allocation");
// D1 — Bare Box allocation + type erasure (no runtime, no channels)
for size in [0usize, 64, 256, 1024, 4096] {
let label = if size == 0 { "zero".to_string() } else { format!("{size}B") };
group.bench_with_input(
BenchmarkId::new("box_alloc_erase", &label),
&size,
|b, &size| {
b.iter(|| {
let msg: Box<dyn std::any::Any + Send> = if size == 0 {
Box::new(NoopMessage)
} else {
Box::new(SizedMessage { _payload: vec![0u8; size] })
};
std::hint::black_box(msg);
});
},
);
}
// D2 — Full send_to for comparison (same sizes as D1)
for size in [0usize, 64, 256, 1024, 4096] {
let label = if size == 0 { "zero".to_string() } else { format!("{size}B") };
group.bench_with_input(
BenchmarkId::new("full_send_to", &label),
&size,
|b, &size| {
b.iter_batched(
|| {
let rt = Runtime::new(make_config(100, 100_000));
let addr = if size == 0 {
rt.spawn(NoopActor).unwrap()
} else {
rt.spawn(SizedSinkActor).unwrap()
};
rt.tick();
(rt, addr, size)
},
|(rt, addr, sz)| {
if sz == 0 {
rt.send_to(addr, NoopMessage).unwrap();
} else {
rt.send_to(addr, SizedMessage { _payload: vec![0u8; sz] }).unwrap();
}
},
BatchSize::SmallInput,
);
},
);
}
group.finish();
}
criterion_group!(
benches,
latency_benchmarks,
@ -731,5 +791,6 @@ criterion_group!(
contention_benchmarks,
placement_benchmarks,
registry_benchmarks,
allocation_benchmarks,
);
criterion_main!(benches);