0 votes

Hello I made a 3D game and it ran fast on my desktop, but became cripplingly slow when i exported it on android. So I'm looking into some uncommon tips and ideas that might work.

Also I've read this link:
http://docs.godotengine.org/en/latest/tutorials/3d/3d_performance_and_limitations.html

Like I said looking for more uncommon tricks. Though I also got some ideas i think might work but I don't know for sure, so please correct me if I'm wrong or tell me if I'm right.

My ideas are:
- Researching a sleep function to add at the end of a long loop.
(An example of a long loop would be AI Path finding)

- Freeing and re-instantiate object instead of hiding and showing them.
(I got this idea thinking that hidden object might actually be occupying ram space despite being hidden. In a scenario where games with so many hidden objects, this might actually make it faster, in theory, if the game just freed up the object and re-instantiate it when needed. Again I am asking if someone could affirm or disapprove my ideas since I don't know how the engine works in this regard)

- Saving and reading player stats from or on a file as oppose to storing it in variables at the start of the game.
(For some this is complicated to explain, so I'll try my best to explain this idea but bare with me as I do. There are arcade games that store the player's score on a variable throughout gameplay. My idea is to save the score on a file instead of storing it in a variable. Why, because variables are either allocated on a stack or Heap. but, both are stored in the computer's RAM. So storing data in temp files instead of variables, in theory, can reduce ram usage)

These are my ideas that I am not too sure will work. Again I am requesting uncommon tips either for back end or for graphics to increase fps. And feedback if my ideas may work because I do not want to rewrite my entire game to check for myself, because that may end up being a pointless endeavor if i am wrong so please send a feed back on this.

asked Dec 18, 2019 in Projects by Xian (164 points)

Just to say, if you use lights in your game it is a known issue(if im not mistaken) that lights cause lags on android or something like that(what a bummer)

Ok, your game is 3D and performance is slow on android.

The first thing I'd do is to connect your android device via USB (you probably already did) and run it directly by one-click-deploy from the editor. That way you can also use the profiler.
Hopefully, Godots profiler can tell at least if gdscript/code is responsible for the slow android performance or not. In the (more unlikely) case that it actually is, you might be able to identify the function which uses most processing time. Then you know where to optimize instead of guessing around.

You can also enable/disable meshinstances / shadows / light sources in the scene tree (there should be tabs to switch from the editor scene tree to the runtime scene tree) while the app is running and watch how the impact on performance is.

But normally, the graphics are the bottleneck on mobile devices. Usually, RAM is not the issue (too much RAM use may only lower the compatibility hence kill the app on low memory devices when it runs out of memory).
The complexity (number of tris/vertices) of Meshes can be an issue but less than one might think.
Most of the time Shaders ARE the issue for low performance. Godot uses/has to use shaders implicitly for many 3D operations. The more shaders have to be used and the more complex shaders are the slower the device will get.

So if you have checked that gdscript performance is OK then focus on optimize GPU performance:

Step one: If possible then use GLES2 instead of GLES3. Ok, GLES2 may look a bit less fancy but its standard shaders are much less demanding on low performing hardware. However, If you use particles, GLES2 will require a different/alternative approach (CPU Particles).

Step two: Optimize lighting/shadows. Shadows require noticable performance as well as shadow filters (project settings). Try to use only one light source (sun?) + maybe ambient lighting whenever possible. Disable Shadows in the profiler to see how much it affects performance. Maybe it is possible to disable receiving and/or casting shadows for certain complex/big meshes.

Step three: Optimize the Mesh complexities. You should be able to see the performance impact when enabling/disabling visibility in the debugger (while running on android). Normally it is not a problem when you've got a player mesh with 10k or 20k vertices. But it IS a problem when you've got 100 trees with each having 10k vertices. Some 3D editors offer methods for lowering the vertices of a mesh. Blender i.e. has a modifier for that. (Always make backups of the original 3d models)

Step four: Have a look on the materials and shaders, especially fragment shaders. And things like relflections/emission.

Now to your questions:
AI path finding. Yes, complex scripts may be a reason for low fps. But this is simple to identify: Temporarily disable the script and run the game on android. If the fps doesn't change -> search elsewhere.

Free-ing and reinstantiateing objects:
If those objects have scripts with process or _physicsprocess attached then those might use some CPU. But you can simply pause the processing when the object is invisible. Other than that free-ing an object will/might save RAM which is not equal to a performance gain. Making an object/meshinstance invisible will normally stop any GPU load from it. Which is what you usually want.

Saving and reading player stats to/from a file
Basically, only save to a file when you need that data the next time the app runs. These are usually thinks like game options, scores, player name.
Do not write often to files on mobile devices. Usually you write when a game option has been changed, when a level was completed, when the game is closed/paused/sent to background. Why? Because mobile devices internally use flash memory. These have a very limited number of possible write operations. If you write ridiculously often to files then this increases "wear" and will kill the device sooner or later. (Ask Tesla owners which paid $3000 for a new on-board computer because Tesla killed the old ones by deciding to write a ridiculous high amount of log data on the flash memory.) So: don't use files to optimize game performance. Use them simply to make data persist.

Is there a reason you focus on RAM usage ?
This might be a reason but its more likely that your bottleneck lies somewhere else.

To find the bottleneck follow @wombatstampede comment (which should probably be an answer rather than a comment)

All your suggestions would in fact make you game run worse btw.

Thanks wombatstampede converting to GLES2 and disabling my scripts and troubleshooting which is causing the slowness has changed the game from crippling slow to slightly slow.

@sleepprogger My mindset is focused on ram usage because I'm a college student and in my classes I am still being taught the computer architecture and how threads works. So I thought focusing on reduce ram usage will increase the size threads can use thus memory is freed quicker for another thread to use XD I'm still not too familiar with other stuff like gpu and how flash memory work so this is actually a great eye opener.

And yeah the bottleneck lies more on the graphical side now.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.