Can we run Havok inside a Web Worker?

Yup! I’m reusing the physics shapes

I’ve added a Stats.js FPS tracker, since previously showing a single FPS value that only updated every second wasn’t as clear

Havok without Worker 2 (~50 FPS)

Havok with Worker 2 (~130 FPS)

If OBS Studio is not recording, the FPS increases by 2-3X, and the physics step computation times decreases by a couple X too

In the Worker, physics step computations seem slightly slower, but the FPS improvement is worth it

Delta time appears to be struggling worse in the Worker, however this is not something to really worry about. It just so happens that the few additional ms per physics step computation in the Worker reached the threshold for the spiral of death. It’s like a Pythagoras cup where if you go just a bit over the edge, things fall behind and cannot recover. Per tick, if running behind on time, the physics is allowed to simulate a maximum of four steps (with timestep 16 ms each) in attempt to catch up to real time, but the Worker struggles to catch up due to a semi-spiral of death. If we add just a few more boxes, I’m sure we can get the Non-Worker to hit this spiral of death too

1 Like