style(simulation): cargo fmt on the workshop benches (gate bounce; clippy and tests were green)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 10:59:34 +02:00
co-authored by Claude Fable 5
parent 4e2d56f40f
commit f44f9a2067
3 changed files with 56 additions and 47 deletions
+7 -14
View File
@@ -38,8 +38,7 @@ use settled_reach_server::seed::{SeedChain, SeedDomain};
/// population is exactly the same 267-body set the hydrology survey already
/// covers, for direct comparability.
fn discover_body_ids() -> Vec<String> {
let wiki_root =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki/star-systems");
let wiki_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki/star-systems");
let mut ids = Vec::new();
fn walk(dir: &std::path::Path, out: &mut Vec<String>) {
let Ok(entries) = std::fs::read_dir(dir) else {
@@ -89,8 +88,7 @@ const PNG_BYTES_PER_CELL: f64 = 638_382.0 / 331_776.0;
#[test]
#[ignore]
fn bench_global_tier_bytes_real_population() {
let systems_db =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data/systems.db");
let systems_db = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data/systems.db");
let reader = BodyParamsReader::open(&systems_db)
.expect("open read-only systems.db (asset-pipeline golden rule: read-only snapshot)");
@@ -129,7 +127,9 @@ fn bench_global_tier_bytes_real_population() {
let total_bytes_raw6 = total_cells as f64 * 6.0; // 6 raw bytes/cell, DistrictWindowLayer's own documented figure
let total_bytes_png = total_cells as f64 * PNG_BYTES_PER_CELL;
println!("\n=== Global-tier (rung 0) byte-cost recheck: REAL population, REAL per-body radii ===");
println!(
"\n=== Global-tier (rung 0) byte-cost recheck: REAL population, REAL per-body radii ==="
);
println!(
" bodies discovered: {}, radius found: {found}, missing/unreadable: {}",
body_ids.len(),
@@ -307,15 +307,8 @@ fn bench_rung0_derive_cost_real_canvas_shapes() {
for col in 0..earth_cols {
let wx = col as f64 * region_m;
let wy = row as f64 * region_m;
let prof = derive_orbital_at_metres(
seed,
"bench",
&earth_body_params,
&ta,
wx,
wy,
&climate,
);
let prof =
derive_orbital_at_metres(seed, "bench", &earth_body_params, &ta, wx, wy, &climate);
std::hint::black_box(prof.elev_q);
}
}
+20 -14
View File
@@ -888,7 +888,9 @@ fn bench_chunk_spacing_4096_cells() {
let seed = SeedChain::root(99).derive(SeedDomain::Body, 1);
let grid_side = 64u32; // 4,096 cells — matches the Block/Tile sweep above
println!("\n=== Interview-2: chunk (64m) spacing derive_at_metres benchmark (4,096-cell sweep) ===");
println!(
"\n=== Interview-2: chunk (64m) spacing derive_at_metres benchmark (4,096-cell sweep) ==="
);
println!(
"grid: {grid_side}x{grid_side} = {} cells/sweep\n",
grid_side * grid_side
@@ -900,7 +902,11 @@ fn bench_chunk_spacing_4096_cells() {
for (label, step_m, cutoff_m) in [
("chunk (64m), cutoff=64m", chunk_m, chunk_m),
("chunk (64m), UNCUT (cutoff=0)", chunk_m, 0.0),
("block (128m), cutoff=128m [reference row]", block_m, block_m),
(
"block (128m), cutoff=128m [reference row]",
block_m,
block_m,
),
] {
let n_cells = (grid_side * grid_side) as u64;
let t0 = Instant::now();
@@ -1068,7 +1074,8 @@ fn build_gj1c_courses_near_window(
for edge in &edges {
let anchor_a = to_world(edge.upstream.0, edge.upstream.1);
let anchor_b = to_world(edge.downstream.0, edge.downstream.1);
let chord_m = ((anchor_a.0 - anchor_b.0).powi(2) + (anchor_a.1 - anchor_b.1).powi(2)).sqrt();
let chord_m =
((anchor_a.0 - anchor_b.0).powi(2) + (anchor_a.1 - anchor_b.1).powi(2)).sqrt();
// Same 0.08 inflation fraction layer_proxy.rs's COURSE_BBOX_INFLATION_FRACTION
// uses (that constant itself is private; the value is stated in its
// own doc and reproduced here for the same bbox-cull purpose — a
@@ -1159,7 +1166,10 @@ fn bench_s2_courses_density_at_chunk_and_block() {
" densest river cell: {best_cell:?} ({best_count} river cells within {radius_px}px radius), world center {center_world:?}"
);
for (label, step_m) in [("chunk (64m)", scale::CHUNK_M as f64), ("block (128m)", scale::BLOCK_M as f64)] {
for (label, step_m) in [
("chunk (64m)", scale::CHUNK_M as f64),
("block (128m)", scale::BLOCK_M as f64),
] {
// Realistic-shape window at this spacing: 64x64 cells (4,096, matching
// this file's other 4,096-cell sweeps for direct comparability).
let grid_side = 64u32;
@@ -1197,9 +1207,8 @@ fn bench_s2_courses_density_at_chunk_and_block() {
for col in 0..grid_side {
let wx = win_x0 + col as f64 * step_m;
let wy = win_y0 + row as f64 * step_m;
let prof = derive_at_metres(
seed, "GJ1c", &params, &ta, wx, wy, &climate, step_m, &[],
);
let prof =
derive_at_metres(seed, "GJ1c", &params, &ta, wx, wy, &climate, step_m, &[]);
std::hint::black_box(prof.elev_q);
}
}
@@ -1226,15 +1235,12 @@ fn bench_s2_courses_density_at_chunk_and_block() {
let ms_on_per_sweep = elapsed_on.as_secs_f64() * 1000.0 / iterations as f64;
let delta_ms = ms_on_per_sweep - ms_off_per_sweep;
let delta_pct = 100.0 * delta_ms / ms_off_per_sweep;
let ns_per_cell_off = elapsed_off.as_secs_f64() * 1e9 / (n_cells * iterations as u64) as f64;
let ns_per_cell_off =
elapsed_off.as_secs_f64() * 1e9 / (n_cells * iterations as u64) as f64;
let ns_per_cell_on = elapsed_on.as_secs_f64() * 1e9 / (n_cells * iterations as u64) as f64;
println!(
" courses OFF: {ms_off_per_sweep:.4} ms/sweep ({ns_per_cell_off:.1} ns/cell)"
);
println!(
" courses ON: {ms_on_per_sweep:.4} ms/sweep ({ns_per_cell_on:.1} ns/cell)"
);
println!(" courses OFF: {ms_off_per_sweep:.4} ms/sweep ({ns_per_cell_off:.1} ns/cell)");
println!(" courses ON: {ms_on_per_sweep:.4} ms/sweep ({ns_per_cell_on:.1} ns/cell)");
println!(
" delta: {delta_ms:+.4} ms/sweep ({delta_pct:+.2}%), {} courses in window",
courses.len()
+29 -19
View File
@@ -303,7 +303,8 @@ fn bench_population_survey_all_committed_bodies() {
use rayon::prelude::*;
use settled_reach_server::atlas::hydrology_equilibrium::{BasinOutcome, DownstreamTarget};
let wiki_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki/star-systems");
let wiki_root =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki/star-systems");
// Discover every committed heightmap PNG (deterministic ordering: sort
// by path so the survey's own reporting order is stable run-to-run —
@@ -357,10 +358,11 @@ fn bench_population_survey_all_committed_bodies() {
.unwrap_or("UNKNOWN")
.to_string();
let heightmap = settled_reach_server::atlas::heightmap::load_heightmap_png(
path, &body_id, 0.3,
)
.unwrap_or_else(|e| panic!("decode committed heightmap for {body_id} ({path:?}): {e}"));
let heightmap =
settled_reach_server::atlas::heightmap::load_heightmap_png(path, &body_id, 0.3)
.unwrap_or_else(|e| {
panic!("decode committed heightmap for {body_id} ({path:?}): {e}")
});
let small = heightmap.downsample(512, 256);
let t_solve = Instant::now();
@@ -439,9 +441,7 @@ fn bench_population_survey_all_committed_bodies() {
println!(
" carved-outlet basins (channel_depth_scaled > 0 at spill cell, summed): {total_carved_cells}"
);
println!(
" cliff_edge=true cells (summed across population): {total_cliff_edge_cells}"
);
println!(" cliff_edge=true cells (summed across population): {total_cliff_edge_cells}");
println!(
" bodies with ANY cliff_edge cell: {bodies_with_any_carving} / {body_count} ({:.2}%)",
100.0 * bodies_with_any_carving as f64 / body_count as f64
@@ -474,12 +474,9 @@ fn bench_population_survey_all_committed_bodies() {
== Some(top.body_id.as_str())
})
.expect("outlier body path must exist (found via the same walk above)");
let heightmap = settled_reach_server::atlas::heightmap::load_heightmap_png(
path,
&top.body_id,
0.3,
)
.expect("re-decode outlier heightmap for determinism spot-check");
let heightmap =
settled_reach_server::atlas::heightmap::load_heightmap_png(path, &top.body_id, 0.3)
.expect("re-decode outlier heightmap for determinism spot-check");
let small = heightmap.downsample(512, 256);
let r1 = solve(&small.data, 512, 256, small.sea_level, default_climate());
let r2 = solve(&small.data, 512, 256, small.sea_level, default_climate());
@@ -634,11 +631,24 @@ fn bench_per_basin_size_distribution_real_population() {
println!("\n=== PER-BASIN SIZE DISTRIBUTION: {n} basins, real 267-body population, 512x256 working grid ===");
println!(" total lake cells (cross-check vs population survey's 2,694,012): {total}");
println!(" min={}, max={}, mean={:.1}, median(p50)={}",
sizes[0], sizes[n - 1], total as f64 / n as f64, percentile(50.0));
println!(" percentiles: p10={} p25={} p50={} p75={} p90={} p95={} p99={} p99.9={}",
percentile(10.0), percentile(25.0), percentile(50.0), percentile(75.0),
percentile(90.0), percentile(95.0), percentile(99.0), percentile(99.9));
println!(
" min={}, max={}, mean={:.1}, median(p50)={}",
sizes[0],
sizes[n - 1],
total as f64 / n as f64,
percentile(50.0)
);
println!(
" percentiles: p10={} p25={} p50={} p75={} p90={} p95={} p99={} p99.9={}",
percentile(10.0),
percentile(25.0),
percentile(50.0),
percentile(75.0),
percentile(90.0),
percentile(95.0),
percentile(99.0),
percentile(99.9)
);
println!("\n Histogram (basin cell-count buckets):");
for (i, (_, _, label)) in buckets.iter().enumerate() {