#324·colyseus

Performance upgrade suggestion for setSimulationInterval

Author: LumyoCreated Apr 13, 2020Updated Feb 19, 2025
Labels🆘 help wanted:mag: research

setSimulationInterval is using setInterval causing a fixed delay timer, once the callback has been called. If the computation is not heavy inside the callback, this isnt really an issue, but when the computation is heavy, the timer will still be applied fully after the callback evaluation is finished.

So if your update logic takes for example 20ms, and your simultation interval is set at 50ms,

Delta time = 20ms (computation time) + 50ms (fixed delay) = 70ms

It could be a significant performance upgrade to have an adjusted value for the timer as: delay = simulationInterval - computationTime (And even just not have any delay when computationTime > simulationInterval)

Here is the result of a test I made with the 2 solutions, with a target of 20 updates/s (50ms) delayTest

Here is the code used for the test : https://gist.github.com/Lumyo/394382f4af628686b81345c5bb3c1a4c

@endel I would be interested to have your thoughts on this.