T-066: Performance pass 2: the step after real physics and metabolism
Goal
The second routine optimisation pass (docs/DESIGN.md section 12, "It never finishes").
Pass 1 (T-063) stayed out of the physics because it was being replaced. Now the real
soft-body physics (T-009) and the metabolism (T-017) are in, and nobody has profiled a step
that contains them. Find where the time and the memory go now, and take the wins.
The aim behind every pass is the same: larger worlds and longer runs on the same machine. Speed per step and bytes per cell both count.
Scope
Start from a profile, not from the list. Run scripts/profile.sh on the benchmark worlds
(docs/perf/worlds/) at 1, 4 and 12 threads and on at least one world of grown bodies
(runner run with genome files, T-065), because a soup of balls does not exercise growth,
bonds of mixed sizes or the metabolism the way real bodies do. Then judge every open idea
in docs/perf/IDEAS.md by measurement and pick by measured gain.
Leads known today. They are examples of the kind of thing to look for, not a list to tick off, and the profile outranks all of them:
- The index build is the largest serial piece of a step (12% of a 4-thread step at 100,000 cells before T-009). A parallel build with one loop and each grid key computed once.
- The physics and the metabolism probably added parallel loops. Each loop wakes the pool's sleeping threads. If stage judging shows the wake-ups, let a stage keep the pool awake across its loops rather than raising the spin for everyone.
- Per-cell memory rose from 120 to about 180 bytes with the development columns, and the physics and metabolism will have added more. Which columns can be smaller, be dropped, or exist only for organisms that need them?
- A growing body rebuilds its neighbour grid on every growth round: 3.3 microseconds per cell for a 65,535-cell body against 0.3 to 0.8 for small ones.
- Stages that allocate inside the loop over organisms, tiny helpers that the profile shows as their own frame, columns read in an order that defeats the cache.
- Anything the new stages do for every cell that only a few cells need.
- One body on one thread. With the placeholder physics a single 65,535-cell body held a
whole world to 1.8 steps/s on any thread count (T-065). Check what T-009's physics does
with it. Very large bodies are a design goal (
docs/DESIGN.mdsection 5, "Scale is free"), so the unit of parallel work should be a bounded amount of work, not a body. - Dense bodies of small cells put hundreds of cells in one index cell.
Out of scope: changing what the simulation computes. Results stay bit for bit the same unless a change is clearly worth a format change, in which case say so in the report and keep it in its own commit so it can be dropped.
Done when
- ☐
docs/perf/LOG.mdhas a profile of the step as it is now: share of time per stage at 1, 4 and 12 threads, bytes per cell by column group, and how speed scales with cores. - ☐ Each change has a
scripts/perf.sh --checkresult before and after in the log, and the suite's history shows the gain. - ☐ No result changes: the same world, bit for bit, on any thread count, native and web.
The determinism tests pass and
scripts/check-unsafe.shpasses (the full check if anyunsafe, column or parallel loop changed). - ☐
docs/perf/IDEAS.mdis brought up to date: what was done, what was measured and dropped, what is new. - ☐ The benchmark worlds still represent the sim. If real bodies behave differently from
the soup worlds, add a world of grown bodies to
docs/perf/worlds/so every later check sees it. - ☐ The next pass is easier: say what you would look at next and why.
Notes
- Keep to 4 threads for anything long, except short measurements that need every core.
- The machine is busy. Trust only paired comparisons (
docs/perf/README.md). - T-051 is the top-down review that plans the big changes once a breeding world exists. This ticket is the routine pass: take what is cheap and measured now.