← Board · source

T-063: Performance pass 1: waste outside the physics

done · M2 · model opus · needs T-050

Goal

The first routine optimisation pass (docs/DESIGN.md section 12, "It never finishes"). Take the wins that are already on the list in docs/perf/IDEAS.md and that do not depend on the physics, which is being replaced by T-009 right now. Every change is measured with the check from T-050 (scripts/perf.sh --check), before and after.

Scope

Judge every idea in docs/perf/IDEAS.md by measurement, pick by measured gain, and do the ones that fit this ticket. Leads known today, as examples and not as a list to tick off:

Out of scope here, because other agents are in those files: the physics (T-009), the metabolism (T-017), the lineage log (T-019), and shrinking the per-cell development columns (wait until T-017 has merged, then it is fair game for the next pass).

Done when

Notes

Result

Branch t-063-performance-pass-1. Numbers and the full tables are in the T-063 entry of docs/perf/LOG.md; ideas are updated in docs/perf/IDEAS.md.

Against the main it started from (scripts/perf.sh --check, load about 10): every case faster or the same. 100k cells: 1 thread -6.9% time, 4 threads -3.5%, 12 threads -15.5%. 10k: 1 thread -6.1%, 4 threads -16.2%, 12 threads same speed with -25.7% CPU cycles. 1M: 4 threads -8.2%, 12 threads -15.6%. Cycles -6 to -26% everywhere.

What changed, one commit each:

  1. The all-cores pool starts on first use, and World::load no longer makes terrain it throws away. Load of a 1024 x 128 x 1024 world 423 to 59 ms; no idle threads left.
  2. Our own fork-join pool (crates/sim/src/exec/pool.rs) replaces rayon. Idle threads spin 5 us, then sleep. CPU wasted against one thread at 10k cells: 12 threads +81% to about +40%, 4 threads +23% to +14%. rayon is no longer a dependency of sim or runner.
  3. perf check judges each stage on its own (25%, stages over 0.005 ms per step). Proved with plants in index, fields and bookkeeping; no false alarm on same code.
  4. runner run/resume --qos CLASS. Default unchanged; initiated measured 1.1 to 2 times faster for the run, about 20% slower for competing work.
  5. #[inline(always)] on the index's grid coordinates: -4% on every case (in the contact queries; no physics file changed).
  6. #[inline] on the per-organism column views: -2 to -3.6%, instructions -4.4%.

Measured and dropped: parallel index build from 50,000 cells (faster alone, not inside a step: cycles +5 to +9.5%, time same). Spin lengths 0 to 100 us and pieces per thread 2 to 32 (chosen 5 us and 8).

Results unchanged: checkpoints byte-identical between main and the branch at 1, 4 and 12 threads (30k cells with churn, 400 steps); determinism tests pass; native and WebAssembly identical for 600 steps (wasm_probe.sh 20000 60 600); full scripts/check-unsafe.sh and --plant pass.

Where the tools got in the way (T-050's tools, first real use):

What I would look at next: the index build is now the largest serial piece (12% of a 4-thread step at 100k); a parallel build with one loop and one key pass. Then measure the pool's wake-up cost once T-009 adds loops. Details in the LOG entry.