Physics performance degradation after a specific number of actors on a scene
Here is a graph with dependency between number of actors and physics time taken. Mechanics is added to compare.
- Source: stats.release.1590101186.zip
- Script: https://gist.github.com/elsid/995c1c6db11d756a292c23726672c91b
- Benchmark video record: https://youtu.be/quo6cTOWjaM
Here is a profile for a scene with 173 actors:
It's noticable that MWPhysics::MovementSolver::move
takes most of the main thread CPU time. This happens because of increased number of calls per actor per frame:
And this is quite interesting because the limit of 20 calls is not reached. And there is an explanation. The game time limit per frame is 200 milliseconds. Default physics FPS is 60. So if consider that each MWPhysics::MovementSolver::move
call represent one frame of physics we can get only 0.2 / (1 / 60) = 12
calls per frame.
Another thing is why we have this limit of 200 milliseconds of game time per frame? The most common FPS for movies is 24. 5 FPS makes game unplayable. Changing this limit to 1 / 24
make situation quite better. 0.045s for 200 actors instead of 0.2s:
And this change confirms the hypothesis with the actual limit of MWPhysics::MovementSolver::move
calls (1 / 24) / (1 / 60) = 2.5
:
The visible effect of the game time limit per frame change is game instead of slide show becomes slow motion. But I'd consider this as an improvement because at least it becomes playable.