Spiky Performance Issue

Hi Everyone,

I have a very simple scene setup.

  • 2 Quads with material - mobile alpha blended (this is used for my background and ground).
  • Spawning Obstacles using object pooling.

My obstacle has 2 collider and a rigidbody. Moving it using rigidbody2d.velocity.

and my background and ground is scrolling using SetTextureOffset.

my project quality settings is set to “fastest”(Vsync = dont sync).
and in my script on Start i am setting the Application.targetFrameret to 60. and Qualitysettings.vSyncCount = 0.

However, the game still lagging and when I try to profile it,
It seems that the game is unstable and vSync is still On.
CPU-
Vsync = 10 - 16ms
CPU Overview -
WaitForTargetFPS = 12 - 15ms
GPU-
Other = 24 - 35ms
GPU Overview -
Camera.Render = 0.7ms

Has anybody experience the same?

Check your graphics driver for forced vsync. And profiling itself takes a hit on performance, so the results are not 100% like when the game runs without it. And targetFramerate is a framelimiter, which can be confused with vsync.

Hi Valoo,
I’m profiling with my android device. how can I check if forced vsync? and can we disable it?
and also, what can you suggest for the setup when building games for android?

Ah, sorry, i don’t own an android device (yet), so i have no experience with those. But collision handling is somewhat costly in Unity, so i would expect a mobile device to be a little less performant. Also if you’re using OnCollisionStay, that may as well be the source of the hickups (it’s implemented via the slow SendMessage() internally). I would suggest to reverse your logic and move the player (one collider) instead of the obstacles (many colliders) and benchmark if it is faster.

Hi Valoo, Thanks for replying.
Hmm. What I did now was, I tried to recreate the project.
Scene setup:

  • add 2 cubes for background and ground.

  • add materials on the cubes

  • add scripts to make it scroll using setTextureoffset.

  • Project Quality settings set to fastest

  • Create empty gameobject(gamecontroller) then add script which sets the vsync count to 0 and targetframerate to 60.

  • build and tried it on Android (Samsung Galaxy S4).

  • I’m still experiencing spiky performance.

Any Ideas? :frowning:

Any other scripts? using GetComponent<>() every frame for example is expensive. Besides that, use the profiler to find slow functions.
Edit: I found this, maybe it helps you too: “Before you build your apk go to the Android player settings, Other Settings, untick ‘Auto Graphics API’ and only add OpenGLES2 do not use 3 or even add it, its performance is terrible” (http://forum.unity3d.com/threads/very-poor-performance-on-android-after-upgrading-to-unity-5.306572/page-11#post-2433520)

Hi ValooFx,
That seems to eliminate the performance issue. :slight_smile:
Thank you verymuch!