- Home /
Android - Inexplicable Lag
Hello!
I am experiencing massive lag when testing on Android devices. Here is an image of what the Active Profiler is displaying:
Obviously, the lag shown here is caused by the Blur Optimized image effect. When I disable the effect, fps returns to about 30. I would like to use the effect, but this behavior is far worse than what is preferred.
Additionally. when more active UI is present, I notice more lag. In a second test, the only UI object was a Text object. This Text object had text which filled the entire screen of the device. Here is the screenshot of the Active Profiler:
Under 30 fps is rather poor. What am I doing incorrectly? I know Unity is more capable than this. Here are some details on my project to help:
In my project, menus are divided into "Manager" scripts. These managers each contain a Canvas Group, and countless UI objects (Text, Button, Image, etc.). There are about 20 such managers, each with 20-100 UI objects. When offscreen, the managers disable themselves (and their UI objects).
I am building for the oldest version of Android possible to feature my game on the largest range of devices. If I remember correctly, I am building in 2.3.1
I am testing on a Kindle Fire HD. Is HD just slow?
In previous tests of previous versions of my game, lag as shown in the first attached image (over 150 ms) was named within the hierarchy as Mesh.SubmitVBO, Mesh.DrawVBO, or SpriteRenderer.RenderBatch.
So just to recap:
Can I somehow use the Blur Optimized Shader?
Why is my game experiencing such lag? It runs 60-120 fps on my computer. Is this normal behavior? How can I correct it?
Here's a picture of the lag experienced in the menus versus in the actual game:
SpriteRenderer.RenderSingle and SpriteRenderer.RenderBatch are still the main culprits. Could the built-in UI Sprite (which I often use) be an issue, as it is not part of the Sprite Packer atlas?
Another picture of lag (notice the jumps between RenderSingle and RenderBatch):
Can somebody please reply? Or at least request more information.
Answer by rutter · Nov 02, 2015 at 10:25 PM
Obviously, the lag shown here is caused by the Blur Optimized image effect.
Mobile and PC platforms have vastly different drawing capabilities. You're invoking some effects that require advanced shaders and numerous draw calls, both of which are going to hurt performance on mobile.
If you don't know what that means, the simplest and best advice is to stick to shaders that are specifically mobile-friendly.
You might also check and make sure that you're using deferred rendering, if that's available with your configuration.
I am building for the oldest version of Android possible to feature my game on the largest range of devices. If I remember correctly, I am building in 2.3.1
Sounds reasonable, but it might be worth checking if newer builds
I am testing on a Kindle Fire HD.
Oof. The Kindle Fire is not a very powerful tablet.
In previous tests of previous versions of my game, lag as shown in the first attached image (over 150 ms) was named within the hierarchy as Mesh.SubmitVBO, Mesh.DrawVBO, or SpriteRenderer.RenderBatch.
If you're seeing a lot of heavy SubmitVBO
calls, you may be using too much geometry in the scene.
It sounds to me like you're writing checks that the hardware just can't cash. Optimization is a big field of study, so you might want to look for some pointers and tutorials.
Thanks for the reply!
I created a new build, using the deferred rendering option, and packed most of my UI sprites into the Sprite Packer. I deleted the BlurOptimized component of the main camera. The profiler showed no apparent increase in fps and no decrease in lag.
I think the key issue revolves around the UI. The game itself runs at about 45 fps; the menus often run at under 15 fps. I would expect the game to run faster than the menus.
At some point, I used the code line Screen.SetResolution(400,800, true);
adapted from http://answers.unity3d.com/questions/1074232/lags-during-tests-on-mobile-spriterendererrendersi.html. Of course, the resolution was goofed up, but it dramatically improved performance. Here is an image before implementing the code (one of the faster UI menus):
After implementing the code:
That is a dramatic change. Beforehand, $$anonymous$$esh.SubmitVBO required 58.53ms; after, it only needed 0.73ms. The only thing "slowing" down the game for the latter was Graphics.PresentAndSync, which I'm assu$$anonymous$$g just caps fps at 60.
Considering how much this line of code improved performance, what is going on? Is the issue the high-definition $$anonymous$$indle spending too much time on rendering? If so, can I alter the code to prevent the use of HD?