bench(pointcloud): sweep points-per-cell density for splats bench

Realistic depth backprojection is dense (many points per 8 cm voxel). Sweep
points-per-cell {4,16,64,256} at n=50k instead of point-count, so the
measurement reflects where the 9-pass→2-pass reduction actually applies.
Parity guard (old≡new, bit-for-bit) holds at every density.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
ruv 2026-06-11 21:44:18 -04:00
parent 2754af804e
commit 67dd539e68
1 changed files with 28 additions and 21 deletions

View File

@ -114,24 +114,28 @@ fn splats_new(points: &[ColorPoint]) -> Vec<Splat> {
/// Deterministic synthetic cloud (no RNG — fully reproducible). /// Deterministic synthetic cloud (no RNG — fully reproducible).
/// ///
/// Points are spread over a room volume that grows with `n` so that the number /// `n` total points distributed so each occupied voxel holds about
/// of occupied voxels scales with the point count (≈ 8 points per voxel on /// `pts_per_cell` points. A real MiDaS depth backprojection is *dense* —
/// average), matching a real dense cloud where the optimization's per-cell /// adjacent pixels at similar depth land in the same 8 cm voxel — so the
/// reduction dominates. This avoids the degenerate "all points in one tiny /// realistic regime is tens-to-hundreds of points per cell, which is exactly
/// cube" layout, which made the measurement noise-bound. /// where the per-cell pass-count reduction matters. We sweep `pts_per_cell`
fn make_cloud(n: usize) -> Vec<ColorPoint> { /// to show the dependence honestly rather than picking a flattering point.
// Side length of the voxel grid (in cells) so total cells ≈ n / 8. fn make_cloud(n: usize, pts_per_cell: usize) -> Vec<ColorPoint> {
let cells_per_side = (((n / 8).max(1) as f64).cbrt().ceil() as usize).max(1); let ppc = pts_per_cell.max(1);
let cells = (n / ppc).max(1);
let cells_per_side = ((cells as f64).cbrt().ceil() as usize).max(1);
let extent = cells_per_side as f32 * VOXEL; // metres let extent = cells_per_side as f32 * VOXEL; // metres
let mut v = Vec::with_capacity(n); let mut v = Vec::with_capacity(n);
for i in 0..n { for i in 0..n {
let t = i as f32; // `i / ppc` selects the cell; the low bits jitter within the cell so
// Three incommensurate strides walk the whole volume, depositing // points are genuinely distinct (non-zero spread → non-trivial scale).
// several points per cell deterministically. let cell = (i / ppc) as f32;
let jitter = (i % ppc) as f32 / ppc as f32 * VOXEL * 0.9;
let base = (cell * VOXEL) % extent.max(VOXEL);
v.push(ColorPoint { v.push(ColorPoint {
x: (t * 0.011) % extent, x: (base + jitter) % extent.max(VOXEL),
y: (t * 0.017) % extent, y: (base * 1.7 + jitter) % extent.max(VOXEL),
z: (t * 0.023) % extent, z: (base * 2.3 + jitter) % extent.max(VOXEL),
r: (i % 256) as u8, r: (i % 256) as u8,
g: ((i / 2) % 256) as u8, g: ((i / 2) % 256) as u8,
b: ((i / 3) % 256) as u8, b: ((i / 3) % 256) as u8,
@ -142,25 +146,28 @@ fn make_cloud(n: usize) -> Vec<ColorPoint> {
fn bench_splats(c: &mut Criterion) { fn bench_splats(c: &mut Criterion) {
let mut group = c.benchmark_group("to_gaussian_splats"); let mut group = c.benchmark_group("to_gaussian_splats");
for &n in &[1_000usize, 10_000, 50_000] { let n = 50_000usize;
let cloud = make_cloud(n); // Sweep density: sparse (few points/cell) → dense (the realistic depth
// backprojection regime). The optimization targets dense cells.
for &ppc in &[4usize, 16, 64, 256] {
let cloud = make_cloud(n, ppc);
// Parity guard: old and new must agree bit-for-bit before we time them. // Parity guard: old and new must agree bit-for-bit before we time them.
let a = splats_old(&cloud); let a = splats_old(&cloud);
let b = splats_new(&cloud); let b = splats_new(&cloud);
assert_eq!(a.len(), b.len(), "cell count differs at n={n}"); assert_eq!(a.len(), b.len(), "cell count differs at ppc={ppc}");
// Sort by center to compare set-equality (HashMap order is arbitrary).
let mut sa = a.clone(); let mut sa = a.clone();
let mut sb = b.clone(); let mut sb = b.clone();
let key = |s: &Splat| (s.center[0].to_bits(), s.center[1].to_bits(), s.center[2].to_bits()); let key = |s: &Splat| (s.center[0].to_bits(), s.center[1].to_bits(), s.center[2].to_bits());
sa.sort_by_key(key); sa.sort_by_key(key);
sb.sort_by_key(key); sb.sort_by_key(key);
assert_eq!(sa, sb, "old/new splat output diverged at n={n}"); assert_eq!(sa, sb, "old/new splat output diverged at ppc={ppc}");
group.bench_with_input(BenchmarkId::new("old_9pass", n), &cloud, |bch, cl| { let label = format!("ppc{ppc}");
group.bench_with_input(BenchmarkId::new("old_9pass", &label), &cloud, |bch, cl| {
bch.iter(|| splats_old(black_box(cl))) bch.iter(|| splats_old(black_box(cl)))
}); });
group.bench_with_input(BenchmarkId::new("new_2pass", n), &cloud, |bch, cl| { group.bench_with_input(BenchmarkId::new("new_2pass", &label), &cloud, |bch, cl| {
bch.iter(|| splats_new(black_box(cl))) bch.iter(|| splats_new(black_box(cl)))
}); });
} }