I’ve been asked to look at some code for a multiplayer game that is cross-platform. (I do not have the code yet and do not know what version of Godot it is using.) On mobile the phone heats up really quickly during gameplay. What are some things I can look for to debug or even measure that when I get the code?
Any ideas?
EDIT: I have been told it is Godot 4.4 (I assume stable but could be .1)
There’s a variety of things to look for, and some of them may not be under your control depending on what else is running on the device, but…
Modern phones have multiple things that can get hot from use; the CPU and GPU, obviously, but also things like the network hardware and GPS. I’d suggest checking whether the game is enabling things it doesn’t need like location services (unless it does need those…) and disabling them.
The game may be throwing too much at the GPU; it would be worth trying things like replacing things with low poly models (if 3D), slowing down or eliminating particle emitters, eliminating translucent things and so forth to see how much effect it has. I’d be drastic about it in the first pass; if the game looks like a tech demo from 1992 and it’s still running hot, the problem probably lies elsewhere. If it runs clean and cool, though, at least you know where a good chunk of the problem lies.
The game is probably trying to do too much on the CPU. All the usual stuff applies here; see if there’s any unnecessary work that can be eliminated, or any algorithms that can be improved. See if there’s anything that can be done incrementally (that is, rather than updating everything every frame, could you get away with updating some things every third or tenth frame and stagger the updates to amortize the load?). Can you get away with squared distance for range checks, for example?
I’m assuming the game is mostly gdscript or perhaps c#, so a lot of lower level caveats about mobile CPUs are probably out of reach, but in general you’re going to be dealing with CPUs that don’t handle cache misses very well. Optimize for code size where possible; a tight loop is vastly better than an unrolled loop on modern hardware, and it’s often cheaper to recalculate things than to have lookup tables as well. It used to be that lookup tables and loop unrolling were faster, and on microbenchmarks they still are, but once they’re in a full-sized project they eat dcache for breakfast and everything gets slower.
Beyond that, it’s really going to come down to the specifics of the project, I think.
It’s a 2D game. It’s not that complex a game from what I’ve seen. My thought is it shouldn’t be doing enough to drive the GPU for sure. But it definitely has networking.
That will be quite hard and annoying to debug.
Especially without access to the original device and only from Godot side, without platform-specific toolchain, like Android Studio, etc.
For some devices and apps this can be completely normal, especially for low-end devices and medium to heavy apps.
Not much to do about it. It is a known bane of smartphone gaming.
In short, high heat is the result of high energy consumption, which is the result of high processing load.
You can use a profiler to try catching what consumes most of the CPU/GPU.
Especially stuff that runs in loops, per frame, in main game loop (_process, _physics_process), etc.
Also consider network operations, those one can be surprisingly hungry on modern smartphones.
On phones with root access, there are tools, that allows to track how much energy each Activity consumes.
Can’t say much about it, haven’t used those.
Look at FPS cap, maybe a simple lock to 60 will solve it.
@dmitrijbes 's point about fps cap is an important one. I’ve seen mobile games that ran hot doing practically nothing because they weren’t frame locked, so they were running the CPU full tilt and submitting frames faster than the GPU could do anything with them. It’s worth noting that on Vulkan, at least by default, if you submit a new frame to the swap chain it will happily overwrite the pending frame, so you can easily wind up doing the work to run at 1000fps and only displaying at 60hz or whatever the screen can handle.
I do have Android Studio installed, and I have VMs of phones I can use. I’ve never tried profiling with them. However, I believe I do have access to the person who reported the overheating (I believe it’s the person hiring me), so I can get them to test it again.
I’ll look into this. Thanks.
@dmitrijbes@hexgrid I’m also wondering now if I can lower the framerate to less than 60. Movies run at 24 frames/sec. I’m thinking I could try dropping it to 30fps.