Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Webgl build fps decrease over time (Chrome)

Discussion in 'WebGL' started by ammar_12435, Aug 29, 2019.

  1. ammar_12435

    ammar_12435

    Joined:
    Jun 28, 2018
    Posts:
    24
    We are working on optimizing our webgl build (intended to be run on chromebooks, chrome latest version).
    Currently we have achieved about ~40 fps throughout the game which is quite near our requirement.

    The issue is that if the game is left "on" for some time (e.g 30-45 minutes), the fps gradually drop from the initial 40 fps to about 20 fps and then continue to decrease in the same manner if game is left on.

    We can say this isnt due to gpu because in all our scenes the draw calls are about 100-150 and they stay constant. Furthermore we have optimized as far as gpu is considered (static/dynamic batching, gpu instancing, disabled shadows, texture compression etc).

    Currently we are unable to profile the actual build (since the development build is about 2gb which cant be loaded in any browser), hence we are profiling the editor.

    Deep profiling the cpu scripts doesnt reveal anything obvious that could be gradually eating up the fps over a period of 45 minutes.

    Has anyone else encountered this in their WebGl builds?
    Any advice for optimization and maintaining a consistent fps?

    Thanks.
     
  2. Logic_Bomb

    Logic_Bomb

    Joined:
    Apr 6, 2017
    Posts:
    16
    There's not much to go on there but the usual suspects for this are:

    - a steadily growing number of gameobjects that run code in the update().
    - gameobjects (or any objects for that matter) that need to keep track of one another. Each new object added creates an exponential burden on the cpu.
    - a steadily growing number of new instantiations of objects each frame. "new" puts a burden on the fps because allocation takes time. Object pools can alleviate this problem - just make sure inactive gameobjects aren't running anything in the Update().
    - a steadily growing list that a fixed number of gameobjects are looping through each Update().
    - objects (including gameobjects) that exist in the scope of the main loop (in gameobjects this would be the Update(), in other objects it would be something referenced in the main loop) that are not being cleaned up properly. This can happen if you have a reference to it from a static class or static collection.
    - misusing InvokeRepeating().
    - browser addons and antivirus software or other software/browser windows/etc running at the same time can sometimes end up being the culprit so it's always a good idea to test on a different machine with a different config.
    - there are probably other things that other devs on here can add to this list.

    Since you can't use the profiler, you will need to create a temporary hud in your game to display stats onscreen. There are many things you could track to find out what is going on, but I would start by reference counting the gameobjects you create minus gameobjects that invoke OnDestroy(), and a separate stat to track each gameobject's Update() on a per frame basis and see if the reference counts match your expectations based on what's on screen. Same thing again if you're using InvokeRepeating() anywhere in your code. Reference count the InvokeRepeating("n") calls minus the CancelInvoke("n") and compare against a per frame number of InvokeRepeating() executions.

    Debugging is the worst. Good luck!
     
    Last edited: Aug 29, 2019
  3. ammar_12435

    ammar_12435

    Joined:
    Jun 28, 2018
    Posts:
    24
    Thanks for the detailed insight. I'll try all these and report back the findings.
     
  4. ammar_12435

    ammar_12435

    Joined:
    Jun 28, 2018
    Posts:
    24
    Unity's audio source was causing the fps drop in the Webgl build. We replaced it with this asset and the fps drop vanished.
     
    Logic_Bomb likes this.
  5. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    267
    You can implement gapless audio with a streaming AudioSource. I use it for my own WebGL game, and it's compatible with Android and iOS! Ping me.
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    You can try doing a Development build, then run e.g. Firefox Profiler (https://profiler.firefox.com/) on the page when the page is first loaded and is running fast, vs after the game is running really slowly, and compare the stack traces to cross-reference what has accumulated into the slow profile. Here is an example output of Firefox Profiler: https://perfht.ml/2nQH1NY
     
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944