jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.78k stars 453 forks source link

Android device overheats and slows down after 5 mins #1338

Open marspixels opened 2 hours ago

marspixels commented 2 hours ago

Hi! I'm integrating a physics engine into my Android game. First I started with bullet but now I'm switching to Jolt

In bullet I have 100 compoundShapes and a heightFieldShape, it runs at 60Hz and update() function takes around 6ms-7ms

In jolt I have 100 staticCompoundShapes and a heightFieldShape. It runs at 60Hz and the Update() function takes around 2ms-3ms with only one thread. That's amazing, but after 5 minutes the Android device starts to overheat and the Update() function takes around 15ms-17ms. It seems that Android activates thermal throttling or something

Although bullet is slower, during the simulation the Android device is cold even for 15 min, and the update() function keeps at 6ms-7ms

In both engines the compoundShapes have the ccd on and sleeping deactivated. Bullet has 10 solver iterations (default config) and Jolt has 10 velocity + 2 position iterations (default config) but disabled deterministic simulation. Both simulations are compiled and run independently

Finally I tried to compile jolt with -O2 and -O1 (rather than -O3) and added this flag "-fno-tree-vectorize". In addition, I added this line std::this_thread::sleep_for(std::chrono::milliseconds(2)); after Update() function to sleep the thread. But nothing of these changes work at all, after 5 minutes the device starts to overheat

Can I configurate Jolt to priorice energy efficiency over speed? I think that this configuration could benefit phones and tablets

jrouwe commented 2 hours ago

Are you using JobSystemSingleThreaded to limit Jolt to a single thread? If so, there should not be any spinloops or the like.

I don't think changing the commandline flags will help.

What I don't understand from your question is if you're running the physics update every 2 ms or if you're running it at 60Hz but that it only takes 2 ms. If you're running at 60Hz, then what are you doing with the 4 ms that you now got extra? Is that time spent sleeping (otherwise it's not really a fair comparison)?

One thing that I can think off that would make Jolt very CPU wasteful is if you misconfigured your broadphase layers so that it needs to constantly rebuild large broadphase trees. Make sure you at least have a layer that contains all the static stuff and one that contains stuff that can move.