# Making physics cheap

# Making physics cheap

Every capability steps at the rate you give it. Most cost grows with *how often* it steps and *how finely* it sub-steps, rarely with how much it models. That makes tuning mostly a matter of three knobs. For the tier table and the governor that turns them for you, see [budgets and tiers](../reference/budgets-and-tiers.md); this page is the by-hand version.

## 1. Sub-steps: the biggest lever

A stiff model (a reactor's prompt neutrons, a circuit's switching) is sub-stepped to stay stable. The sub-step is a cap, `maxSubstep` (`maxStep` on a `Circuit`), and a long, slow process does not need the fine one:

```ts
reactor.maxSubstep = 0.5;     // a coast: coarse
reactor.step(1);
```

Fine sub-steps while something fast is happening (rods moving, a reactivity step); `maxSubstep` of 0.25 to 1 for a coast. A coarser sub-step makes the call several times cheaper and a coast gives the same temperatures and decay heat either way. The same holds for `Circuit` and `Boiler`. The comparison is in `tests/unit/examples/physics-scenarios-tuning.test.ts`.

## 2. Step rate: most things do not need 60 Hz

| Model | Time constant | A sensible rate |
|---|---|---|
| Heat network, a steel part | tens of seconds | 2–10 Hz |
| Liquid network (pipes, cellar) | seconds | 10–20 Hz |
| Boiler, chemistry vessel | seconds | 10 Hz |
| Reactor coast | minutes | 1 Hz, `maxSubstep` 0.25+ |
| Circuit with a switch | ms | per frame, sub-stepped |
| Bodies, strength, impact | frame | the host's fixed step |

Step slow models from an accumulator, not every frame: add the frame time to `acc`, and when `acc >= 0.2` call `net.step(acc)` and zero it, passing the true interval so the energy is right.

## 3. Switch off what nobody can see

| Situation | Switch | Costs you |
|---|---|---|
| A room the player left | stop stepping its networks; keep the numbers | a jump when they return: advance by the elapsed time in one coarse step |
| Far-away fragments and debris | thin the effects (see [fx](../reference/fx.md)) | prettiness, not behaviour |
| A static structure | leave it asleep; wake it on a hit | nothing |
| A long coast (decay heat, cooling) | one big `step(3600)` | nothing, if the model is linear over the span |

## Order of removal

When the frame is over budget, give up in this order: fx particles, then step rates of slow models, then sub-steps, then off-screen simulation. Do not touch the rigid-body step before these; it is what the player's hands feel.
