Hi all!
I recently played my game on mobile (HTML5) and looks like I have a pretty annoying problem:
Desktop (Defold) => no issue
HTML5 Desktop => no issue
HTML5 Mobile => frequent crashes
I’m not a performance optimization expert but the way the game is crashing (always in the same conditions / after playing 3-4 battles, cf the “walkthrough” below) made it look like a “memory” issue.
I must say this is both depressing and scary because I never took care of that kind of stuff until now (I’m a game designer, not a developer… But I want the experience to be as fluid & bug/crash-free as possible). The game did not crash on mobile until now and the game run at 60FPS so I did not dig deeper and just kept adding features. But this time it looks like I have no other choice…
So I decided to take a look at the web profiler, for the very first time…!
—-------------
Performance walkthrough (maybe it’ll help understand the issue) :
1/ At launch, the main scene and all the characters are loaded (as they will be every time I’ll get back to the main scene).
At this point, Memory (and CPU) are already yellow/orange/red:
I don’t know if this baseline is acceptable or not (274k), but from now on it will only get bigger :)…
2/ Then I display the World Map (popup):
=> instant 335k when launched
But a few seconds later:
back to 295k
Note: even after closing the popup, it stays at this level
3/ And finally I launch a battle.
And this is where there is something that could be investigated/improved but I’m not sure.
Some sort of “memory spike” (up to 700k!) when the scene is loaded:
The scene itself is not that crowded (once everything is on track), but at the moment the collection is created, many elements are spawned/calculated within a small delay (my army, the enemies, the tilemap parts etc.)
After X battles (depends on how lucky I am :’) ), the games crashes with various similar symptoms.
** Black screen*
** Chrome error message (can’t open the website)*
** Or the game restarts by itself*
But I feel that the cause is the same.
4/ Back to world Map
After the battle, the memory usage stays steady at ~340k
Like some stuff is still used in memory, but I don’t know what/why…
On device, impossible to launch a battle from a certain point -like 3-4 battles, like the updated baseline is too high and the accumulation created a “memory debt” or something.
—-------------
A few questions (because to be honest, I don’t really know where I should start…)
Based on your experience…
1/ Do you think this is a memory issue, or something else? If it’s not, how to identify the issue?
2/ What is the memory usage that I should never exceed to make it work on mobile? (if there are guidelines => in my case maybe the baseline level seems ok but the spikes may be a problem)
3/ What are the good/bad practices to optimize memory usage?
Ex: delay some element creation by 1-2 frames to avoid bottlenecks etc. Is this something that is commonly done? But there may be many other things, ex: reduce tilesource image as much as possible etc.
4/ Is there a way to “clean/purge” the memory (to some extent)? Because as said above, it’s like, even without the spike, there is an “accumulation” of memory usage (particularly when going from world map to battle and vice versa).
=> When a collection is unloaded via Monarch, the allocated memory is not supposed to be “freed”?
5/ What is the best method to efficiently test a game on mobile? For now, I created HTML5 bundles, put them online, and test them… Each iteration takes time in these conditions, but I was just checking that the game was playable on mobile.
6/ Any other advice? (ex: how to make the most of the profiler)
—-------------
Thank you!