Performance
The most expensive part of rollback is "when a prediction was wrong, go back N ticks and simulate N ticks again". DetPhys sets its budgets by whether that fits in one frame. The number of bodies and the prediction window N are settings. Use the numbers below to choose the bodies, shapes and N for your game.
Budgets (fit one frame in 4 ms)
| Device | Budget |
|---|---|
| Mid-range PC | 60 Hz, 200 concave dynamic bodies, N = 10 (re-simulate 10 ticks in one frame) within 4 ms |
| Mobile (Galaxy S9 class) | 60 baked concave bodies with N = 10, or 100 bodies with N = 6, within 4 ms |
- Devices: PC = Core i7-12700F / Windows 11 / power plan "High performance"; Galaxy S9 = SC-03K / Snapdragon 845 / Android 10.
- "One frame" = restore N ticks back → re-simulate N ticks (taking a dyn snapshot into the ring on each) → advance one tick, averaged over 300 frames, with every body awake: the worst case.
- In real matches mispredictions are rarer and roll back fewer ticks, so the average is a fraction of this (see "Real sessions" below).
2D rollback cost (200 bodies, N = 10, 60 Hz, 4 substeps)
| Shape (convex polygons per body) | PC, 4 workers | PC 4 ms | Galaxy S9, 4 workers | S9 4 ms |
|---|---|---|---|---|
| Simple shapes (1) | 1.16 ms (0.87 with 1 worker) | fits | 3.36 ms (3.14 with 1 worker) | fits |
| Hand-made concave compounds (5.6) | 2.00 ms | fits | 6.14 ms | 1.5× |
| Baked shapes, steiner (9.4, default) | 3.50 ms (3.27 with 8 workers) | fits | 10.8 ms | 2.7× |
| Baked shapes, hm (10.2) | 4.09–4.16 ms | borderline | 12.9 ms | 3.2× |
- Conditions: PC scheduled by the OS (no core pinning); S9 pinned to its 4 big cores. With 1 worker, baked shapes (steiner, 1886 convex polygons) took 5.99 ms on the PC and 16.36 ms on the S9.
- Bodies that fit N = 10 in 4 ms on the S9: about 124 hand-made compounds, about 70 baked steiner shapes, about 60 baked hm shapes. For 100 bodies, N ≈ 6.3–6.7.
- Almost all the time is the step (78% of the frame for hm on the S9). It grows almost linearly with the number of convex polygons, so raising the baker tolerance (
epsilon_px) to get fewer pieces makes it lighter. - Taking snapshots only on confirmed ticks gives 2.98 ms (steiner) and 3.45 ms (hm) for 200 baked bodies on the PC (4 workers).
3D rollback cost (200 bodies, N = 10)
200 boxes, spheres, capsules and convex hulls (207 in all, almost all awake) built through the C ABI (detphys3d.h); "roll back 10 ticks → re-simulate 11 ticks (a full snapshot and a hash every tick)", averaged over 1,589 frames. PC = i7-12700F, msvc-x64 Release, pinned to P cores; S9 = pinned to the 4 big cores.
| Condition | One frame | One tick step | Snapshot / restore (full) |
|---|---|---|---|
| PC, 1 worker | 5.17 ms | 0.40 ms | 0.047 / 0.067 ms |
| PC, 4 workers (core's pool) | 3.15 ms | 0.22 ms | 0.044 / 0.068 ms |
| PC, 4 workers (Box3D's built-in) | 3.37 ms | 0.24 ms | – |
| Galaxy S9, 1 worker | 17.3 ms | 1.22 ms | 0.29 / 0.22 ms |
| Galaxy S9, 4 workers (core's pool) | 13.5 ms | 0.86 ms | 0.30 / 0.24 ms |
- Only the PC with 4 workers fits 4 ms. On the S9 it is almost all step time. The full image is at most 722 KB (1,265 contacts); a dyn snapshot is only 9% smaller.
- This table is the heaviest case (every body awake, rolling back 10 ticks). Real 3D sessions are much lighter, as the next table shows.
3D sessions (real time, two peers in one process, 3600 ticks, N = 10, 1 worker, full)
3D push (two sphere players, boxes, spheres, convex hulls; 115 bodies, 7.7 awake on average) and 253 bodies that never sleep (230 awake). Per frame average / p99 / max [ms] of the worse peer. PC pinned to P cores, S9 pinned to big cores.
| One-way delay, loss | Delay | B/tick | 115 bodies PC | 115 bodies S9 | 253 bodies PC 1 worker | 253 bodies S9 1 worker |
|---|---|---|---|---|---|---|
| 0 ms | 0 | 32.2 | 0.032 / 0.116 / 0.633 | 0.144 / 0.363 / 0.627 | 0.231 / 0.519 / 0.743 | 1.103 / 2.298 / 2.549 |
| 30±10 ms, 5% | 0 | 33.2 | 0.034 / 0.141 / 0.269 | 0.155 / 0.558 / 0.859 | 0.249 / 0.869 / 1.376 | 1.194 / 4.279 / 5.463 |
| 100±20 ms, 10% | 0 | 36.4 | 0.041 / 0.265 / 0.513 | 0.190 / 1.172 / 1.995 | 0.304 / 1.809 / 2.575 | 1.462 / 8.402 / 9.564 |
| 135±15 ms, 20% | 0 | 39.2 | 0.043 / 0.335 / 0.636 | 0.196 / 1.466 / 2.293 | 0.323 / 2.321 / 2.736 | 1.527 / 10.455 / 11.649 |
| 135±15 ms, 20% | 2 | 38.6 | 0.043 / 0.290 / 0.514 | 0.191 / 1.195 / 1.697 | 0.313 / 1.891 / 2.405 | 1.476 / 8.525 / 10.469 |
- The PC fits 4 ms even with 253 never-sleeping bodies at 135 ms one way (max 2.7 ms). On the S9, 253 never-sleeping bodies push p99 over 4 ms once the delay exceeds 30 ms (one re-simulated tick ≈ 1 ms). A normal scene with 115 bodies stays at 2.3 ms max even on the S9.
- When most bodies sleep, the full snapshot (0.08–0.10 ms on the S9) costs more than the step.
- PC and S9 as two processes (UDP, 1800 ticks): per frame PC 0.08–0.15 ms average, S9 0.20–0.29 ms average (max 1.9–4.0 ms).
- Turn-based 3D (stacking convex hulls, up to 12 bodies): 89 B per turn, resync state at most 43 KB.
3D moving concave shapes
Two scenes for detphys3d_. 60 Hz, 4 substeps, gravity −10 m/s², 1 worker, default splitting (up to 4 pieces, 20 mm), full snapshots. PC = Windows x64, msvc-x64 Release; S9 = Galaxy S9 (SC-03K, Android 10), android-arm64. Neither was pinned to cores.
- Scene a: one spinning concave gear (an octagonal platform + 3 dividers + 12 rim walls, 1.2 rad/s; radius 3.26 m to the corners of the rim walls, so every tick is split into 4).
- Scene b: four moving platforms (back and forth with holds, lift, orbit, sway; all concave trays; no splitting).
| Condition | PC | S9 |
|---|---|---|
| One tick (with splitting and update), a: 1 kinematic, 24 dynamic boxes | 0.10–0.12 ms | – |
| One tick, b: 4 kinematic, 20 dynamic boxes | 0.04 ms | – |
| One rollback frame (full restore + 10 ticks), a / b | 1.1–1.3 / 0.43–0.51 ms | – |
| 200 dynamic bodies, a: one tick step | 0.254 ms | 1.01 ms |
| 200 dynamic bodies, a: restore + 10 ticks, mean / max | 2.64 / 4.55 ms | 10.3 / 18.6 ms |
| 200 dynamic bodies, b: one tick step | 0.097 ms | 0.39 ms |
| 200 dynamic bodies, b: restore + 10 ticks, mean / max | 1.01 / 2.61 ms | 4.1 / 10.9 ms |
| One advance of a real-time session (two peers in one process), a / b | 0.14 / 0.055 ms | 0.49 / 0.18 ms |
| Full snapshot size, a / b | 97 / 49 KB | same |
- With 200 dynamic bodies on a gear split 4 times every tick, the maximum of restore + 10 ticks is 4.55 ms on the PC, a little over the 4 ms budget. The number of pieces depends on the spinning platform's bounding radius and speed (a smaller or slower platform, a larger
subtick_move_mmor a smallermax_subticksis lighter, traded against the tunneling speed). - On an S9, 200 dynamic bodies with N = 10 do not fit in 4 ms (as in the 3D rollback table above, the step is almost all of it).
Real sessions
| What | Conditions | Result |
|---|---|---|
| Real time, two peers in one process | Push scene with 77 / 205 bodies, N = 10, 3600 ticks, 5–150 ms one way and 5–20% loss injected | Worst frame: PC 2.0 ms or less in every condition. S9 4.2 ms (p99 3.9) only with 205 bodies, fast-changing inputs, 135 ms one way and 20% loss; 4 ms or less otherwise. Re-simulation averaged 0.06–2.3 ticks per frame, at most 10 |
| Real time, PC and S9 as two processes (UDP) | 77 bodies, 1800 ticks | Per frame: PC 0.08–0.12 ms average (max 1.4), S9 0.23–0.36 ms average (max 3.0, pinned to big cores) |
| Unity push sample, PC and S9 | 1800 ticks, Wi-Fi LAN | S9 at 59.8–59.9 fps. Core per frame (poll + advance + C# rule) 0.8–1.35 ms average, p99 3.3–4.0 ms |
| Same sample with the moving field (gear, platform, lift) | Same | S9 at 59.7–59.9 fps. Core 1.70–1.91 ms average, p99 3.9–7.5 ms. No tunneling. A Unity 2022.3 APK also ran at 59.9 fps, 1.87–1.88 ms average |
| Godot push sample (the core's built-in rule), S9 against Unity (PC) | Moving field, 1800 ticks, 80 bodies | S9 core 0.91–0.95 ms average, p99 1.8–2.2 ms (step 380 µs, snapshot 51 µs, restore 83–90 µs), 32.3 B/tick. Godot on the PC 0.13 ms per frame (0.18 ms with the moving field) |
| Built-in push (core) against the same rule written in C++ / C# | PC, 205 bodies | The difference is within the noise (core 0.197–0.207 ms, former C++ 0.202–0.213 ms). With the moving field about 2× (splitting, and boxes do not sleep) |
| 4 moving concave shapes + 200 dynamic bodies | One frame with N = 10 | PC 0.58 ms (1.14 ms on split ticks), S9 2.3 ms (4.7 ms while splitting) |
| Turn-based (stacking) | Two peers in one process, 196 ticks per turn on average | One turn per peer: PC 1.25 ms, S9 4.6 ms |
| Unity stacking sample, PC and S9 | Automatic fast play | poll: PC 1.3–1.6 ms, S9 5.6–8.0 ms. One turn (wall clock) 13.5–20.8 ms on average |
On the S9, running without core pinning and with idle time can show about 2 ms average and 24 ms worst because of OS scheduling (the Unity rows above were measured inside the engine frame).
Traffic
| Item | Amount |
|---|---|
| Real time (inputs, acks, hash checks) | 32–48 B per tick one way (without UDP / IP headers) |
| Turn-based (stacking) | 150–190 B per turn for both peers together |
| State sent on a resync (full) | about 184–190 KB for 77 bodies, about 415 KB for 205 bodies (about 1.5 s at 135 ms one way) |
| 3D real time (inputs, acks, hash checks) | 32.2–39.2 B per tick one way (up to 43.5 B between two processes) |
| State sent on a 3D resync (transfer) | 190–260 KB for 115 bodies (0.1–0.2 s between a PC and an S9). Not compressed yet |
| Largest datagram | 55 B with inputs and checks only. Resync state chunks are 1051 B (real time) and 1057 B (turn-based) with chunk_bytes 1024. How this fits a transport's limit: 8. Transports and room codes |
Right after a resync the guest re-simulates many ticks at once (205 bodies, 135 ms one way: 90 ticks in one frame, 8.2 ms on the PC).
Snapshot size and time (2D, 200 bodies)
| Item | PC | Galaxy S9 |
|---|---|---|
| dyn snapshot (200 concave bodies) | 0.037 ms | 0.11 ms |
| restore (in place) | 0.046 ms | 0.11 ms |
| Size | dyn 544–592 KiB / full 836–885 KiB | same |
Engine layer cost
Creating a scene of 116 bodies, running 600 ticks and hashing: Unity Editor 14–16 ms (2022.3 also 14.5–15.3 ms), S9 APK 54–58 ms; Godot (headless) 15–17 ms, S9 55–75 ms; Unreal (UE 5.8.4 editor, -nullrhi) 14.7 ms. The hash is the same in every engine.
Tuning
| Knob | Effect |
|---|---|
| Body count, convex polygon count | The biggest effect. A larger baker epsilon_px gives fewer polygons |
Prediction window N (max_prediction) | Smaller means a lighter worst frame; too small means more waiting with distant peers |
| Input delay, automatic input delay | Fewer mispredictions (traded against the feel of zero delay) |
Workers (worker_count) | Helps with about 200 concave bodies; with few or simple shapes 1 worker is faster. The hash does not change |
| Snapshot kind | dyn (default) is faster for real time. Raise snapshot_ if shapes change often |
Hash check interval (hash_interval) | Every tick by default; hashing costs little |
Splitting of moving concave shapes (max_subticks, subtick_move_mm) | A split tick costs that many steps. Slower motions or fewer splits are lighter (traded against the tunneling speed). In 3D the fastest point is measured with the shapes' bounding radius, so large spinning platforms split more |
| Desync debugger | Zero when off (default). 5–20 µs per tick when on (3D with about 70 bodies: 15–19 µs on a PC, about 175 µs on an S9) |