-
Notifications
You must be signed in to change notification settings - Fork 127
Performance: Skip work in Update Kinematic Bodies if object has not moved since last update. #847
Description
Description
I setup a map in which I am only player (no AI), and removed critters such that nothing is actively moving.
It seems items and other kinematics are going down paths for shoving out of objects, and checking if should fall through ground running collision detection. Some bodies do check falling path and take 100ms, others seem to do shove -> check falling for 50ms each, cumulative cost seems to be 100ms consistently per object.
The 50ms cost of shove out of objects is just for collision detection, is higher if actually shoving out.
I am interested in exploring if we can "sleep" items that are not moving or interacted with. Basically if gravity is the only force acted on them, we know they should end up in the same spot as last frame, and can skip collision tests with static objects such as tilemap.
Probably should proceed with care, as these types of sleeping optimizations are easy to do wrong / get bugs, but I believe we should be able to shave something close to 1.5ms off of each game update. Possibly more in a map with more items.
Example of update loop with no critters, one player not moving, and items laying around map:
I expect this should have an impact on #846