Reduce Matter.js Iterations on Low-Power Devices

Simulating rigid-body physics on resource-constrained mobile hardware requires balancing performance and simulation stability. In Matter.js, lowering engine.positionIterations drastically reduces CPU consumption and thermal throttling, but it frequently introduces stack instability, resulting in jitter, body penetration, and collapsing structures. This article outlines practical architectural adjustments, engine parameters, and physics design choices to safely decrease position iterations without compromising the integrity of stacked objects.

1. Normalize Mass Ratios in Stacks

Physics solvers struggle to resolve contacts between bodies with vastly differing masses using low iteration counts. When a heavy body sits on a lighter one, low position iterations cause the heavier object to penetrate the lower object, producing spring-like jitter.

2. Tune Collision Slop and Restitution

The slop property dictates the depth by which bodies can penetrate before position corrections trigger. Increasing this value prevents the solver from violently over-correcting slight overlaps at low iteration counts.

3. Aggressively Enable Body Sleeping

The most effective way to run low iterations without stack collapse is to remove resting stacks from the simulation loop altogether.

4. Adjust the Balance Between Solver Passes

Matter.js decouples constraint calculations into positionIterations and velocityIterations. While position iterations correct overlap, velocity iterations resolve kinetic impulses.

5. Utilize Chamfered Geometry

Sharp 90-degree corners on stacked boxes cause erratic contact normals when objects overlap under low solver precision.

6. Clamp Variable Delta Time

Mobile web environments frequently experience frame drops, leading to large, unpredictable time-step deltas (dt). When dt spikes, a low-iteration solver fails completely, causing stacks to explode.