What does mobile game optimization cover?
Players never see your profiler. They see a game that stutters, a phone that gets hot, a battery that drops during a commute or a loading bar that takes too long. Each of these problems has a technical cause you can measure and fix.
- Frame rate and frame time. How many frames per second the game shows and how even the frames are.
- Memory. How much RAM the game needs at its peak, and whether that number grows during a session.
- Battery and heat. How much power the game uses in a long session.
- Load time. How long the player waits from the icon to the first moment of play.
- Build size. How much the player has to download from the store and keep on the phone.
It pays to look at all five together. One texture fix often improves memory, load time and build size at once.
Start with a frame budget
At 60 frames per second each frame has about 16.7 ms for game logic, physics, animation and rendering. At 30 fps the budget is about 33.3 ms. Choose the target early, for each type of device. A puzzle game can show menus at 30 fps and gameplay at 60. A fast action game needs 60 fps on mid-range phones and a stable 30 fps on the cheapest ones.
Watch frame time more closely than the average fps. A game with a good average and regular spikes of several frames feels worse than a game that holds a steady 30 fps. The usual causes of spikes are garbage collection, loading assets during play, shader compilation on first use and sudden bursts of particles.
Profile on a real phone before you change anything
Guessing wastes time. Play a typical session on a real phone with a profiler connected, find the slowest part and fix that first. Then measure again.
- Defold. The built-in profiler runs on the device, and you can view it on screen or in a browser. You get frame time, draw calls and memory for each part of the engine.
- Unity. Connect the Unity Profiler to a development build on the phone. Use the Frame Debugger to check draw calls and the Memory Profiler package to find what takes up memory.
- Android. With Android Studio profilers, Perfetto system traces and Android GPU Inspector you can see CPU, memory and GPU work on the device.
- iOS. Xcode Instruments, with Time Profiler for CPU and Allocations for memory.
Measure a build that is close to the release build. In the editor and in debug builds there is extra overhead, and some problems do not show up at all.
Cut draw calls with texture atlases and batching
Every draw call costs CPU time. On a cheap phone you can afford far fewer of them than on a desktop graphics card, so draw calls are often the first thing to fix in a 2D game.
- Pack sprites into atlases. Put images that appear on screen together into one texture atlas. In Defold, sprites that share an atlas, material and blend mode can be drawn in one batch. In Unity you get a similar effect with Sprite Atlas and the SRP Batcher.
- Keep the draw order in mind. If objects from different atlases are mixed in the draw order, you lose batching. Group them by layer.
- Reduce overdraw. Large transparent images stacked on top of each other cost a lot of GPU time. Trim empty pixels, use opaque materials where you can and keep full screen effects to a minimum.
- Simplify the interface. Fewer layers, fewer masks and fewer fonts in one screen mean fewer draw calls.
Write down the draw call count before and after each change. It is the easiest way to see whether the atlas work paid off.
Keep memory under control
When a game uses too much memory on Android or iOS, it gets closed by the system, often without a crash report. On a phone with 2 or 3 GB of RAM a game gets much less memory than the spec sheet suggests, because the system and other apps need their share too.
- Start with textures. In most games they are the largest part of memory. Use compressed GPU formats such as ASTC or ETC2 and lower the resolution of textures that players only see small.
- Load and unload content per level. With collection proxies in Defold, or Addressables in Unity, you can keep in memory only what the current scene needs.
- Stream long music. Keep long tracks streamed or compressed and decode only short sound effects.
- Avoid garbage in the game loop. In C#, avoid allocations in Update, cache component lookups and use object pools. In Lua, reuse tables and vectors in code that runs every frame.
- Look for leaks. Restart the same level ten times and check whether memory goes back to the same level each time.
Save battery and avoid heat
Players uninstall games that drain the battery. Heat is a performance problem too. When a phone gets hot, its CPU and GPU clocks are lowered to cool it down. That is why a game that runs at 60 fps for the first five minutes can drop much lower after twenty.
- Cap the frame rate. Menus, map screens and turn based games rarely need 60 fps. In Defold you set the frame cap in game.project. In Unity you use Application.targetFrameRate.
- Stop work nobody sees. Pause particles and animations off screen and skip game logic on idle screens.
- Lower the render resolution on weak phones. Rendering at a lower internal resolution and scaling up saves a lot of GPU time, and on a small screen the difference is hard to notice.
- Group network calls. Send analytics events in batches and avoid polling the server every few seconds.
- Test long sessions. Play for 20 to 30 minutes with the phone in your hand. A two minute test will not show heat problems.
Shorten the load time
Players judge a game in its first seconds. If the first load takes long on mobile data, some of them leave before they see the menu.
- Get to play quickly. Load the menu and the first level first, and the rest in the background.
- Split the content. Decide what the first session needs and what can wait for later levels.
- Load asynchronously. If you block the main thread for a long time, the loading screen freezes and the player may see an ANR (Application Not Responding) dialog on Android.
- Prepare during loading. Warm up shaders and fill object pools while the loading screen is visible, so the first fight does not stutter.
Keep the build size small
The download size is visible on the store page, and players with little storage or a limited data plan look at it. A smaller build is easier to install and easier to keep on the phone.
- Read the build report. After a build, you will find the largest assets listed in the Unity Editor log. In Defold you can generate a build report with the size of every resource.
- Remove what you do not use. Delete unused assets, plugins and SDKs. In Defold you can leave out engine parts the game does not need with an app manifest. In Unity, turn on code stripping and remove unused packages.
- Compress for each platform. Set texture and audio compression per platform, so each build gets the formats its devices support.
- Use Android App Bundles. With them, players download only the files their phone needs for its CPU and screen density.
- Download extra content later. Move optional levels, skins and languages to downloads after install, for example with Play Asset Delivery or your own content server.
Plan for low-end Android phones
Most performance problems show up first on cheap Android phones. They have slow storage, weak GPUs, little memory and older Android versions. If the game runs well on them, it will run well almost anywhere.
- Keep a small set of test phones. One low-end Android phone, one mid-range Android phone, an older iPhone and one current flagship are enough to catch most problems.
- Check real player data. Open Android vitals and the device catalog in Google Play Console to see which phones your players use and where crashes, ANRs and slow sessions happen.
- Add quality levels. On weak phones, lower the resolution, use fewer particles and simpler shaders. Choose the level at the first launch from a short benchmark or a device list, and let players change it in the settings.
- Test hard conditions. Try the game with almost full storage and with battery saver turned on. Many problems appear only then.
Testing on real devices
The editor and emulators run on desktop hardware, so heat, memory limits, slow storage and touch latency are missing there. Use them to test logic, and use real phones to test performance.
- Play the same test route every time and write down frame time, peak memory and battery drop.
- Test a fresh install, a return from the background and a long session.
- Test on a slow mobile connection.
- Repeat the tests after every larger content update.
With cloud device farms such as Firebase Test Lab you can check many phone models at once. For feel and heat you still need a phone in your hand.
How mobile optimization helps web and HTML5 builds
A browser game on a phone has the same limits as a mobile app, plus a few more. The browser uses memory too, there is no install step, and players leave quickly when loading takes long.
Most of the work above carries over. With atlases you get fewer draw calls in WebGL. If you compress textures and audio, the download gets smaller. If you load the game in stages, the first download stays small, and web portals ask for exactly that. A frame cap and quality levels are as useful in a mobile browser as in an app.
If you plan a browser version, our guide to HTML5 game optimization covers the web specific steps, and the article on porting a mobile game to the browser covers the product side.
Does the engine matter?
Optimization is easier when the engine fits the game. Defold has a very small runtime, and you can remove engine parts you do not use, so 2D and light 3D games stay small on phones and on the web. In Unity you have more tools for 3D, and a well tuned Unity build runs well on mid-range phones, but it takes more care with build size and memory. Our Defold vs Unity comparison goes into the details.
When to bring in an outside team
Teams often leave optimization for the end of a project, when the release date is close and the team is busy with content. An outside team with low-end device experience can profile the game, fix the worst problems and add quality levels while your team keeps working on features. Our guide on how to outsource game development explains how to brief a studio.
Codeward is a game studio from Kraków with many client projects behind it. We build and optimize mobile and web games in Defold, and our team has years of Unity and C# experience, so we also work on existing Unity projects. If your game also needs a browser version, see our web game porting service. For wider help with production, read about us as a game development outsourcing company.