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. Dismiss Notice

Frame-rate drops at game beginning on iOS safari?

Discussion in 'WebGL' started by OceanX000, Feb 25, 2021.

  1. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Hi, when playing our games on iOS(iPhone7,8) safari, it seams FPS is very low. For example:
    1. At the beginning, FPS is less than 20 and also some janks. When monitor in xcode instrument, corresponding webcontent process cpu ls high(nearly 150~200%).
    2. if play a little longer(maybe 2 min or more), FPS recover to 40(CPU is around 60~80%).
    The first minute is very import to players. If game performance is low and players feel your game is boiling theirs phone, they will be lost.

    After some research, I guess it relates to webkit WebAssembly Compilation mechanism?
    In order to launch quickly, webkit use LLint(baseline compiler), then AIR generated in the background. So I think the reason maybe:
    1. LLint performance is bad
    2. AIR generation eat-up too much CPU resource

    Then, all about this is related to WASM CODE SIZE. Most of our game's uncompressed code size is nearly 30M and very hard to shrink by a large margin.

    Or is there other reason? Thanks in advance.
     
    Last edited: Feb 25, 2021
    TallJohn likes this.
  2. TallJohn

    TallJohn

    Joined:
    Dec 3, 2019
    Posts:
    12
    I looked into it recently too. You can see it on smashkarts.io if you play on any iOS device (obviously it is easier to see on older devices). It will be slow for the first 30seconds or so.

    Getting it to work on mobile WebGL was a challenge with a few different issues to overcome along the way. But this was the only issue we have not been able to solve. For me this is the biggest issue with Unity WebGL on mobile. Apart from this it runs really well and our % of players on mobile is growing.

    I connected from iPhone to Unity profiler yesterday and could see nothing weird going on with the game that would cause these slowdowns. So hopefully @Ocean2021 is correct in his assumptions and it will help the team figure out a solution to the problem.
     
    De-Panther likes this.
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    This is something that has been on the radar for a long time. We do have codegen size research projects going on, and they are becoming more important especially now that we are aiming to enable support for mobile browsers.

    One thing I am curious about is whether after the execution gets fast and you reload the page, does it run fast then immediately? I.e. I wonder if Safari successfully caches the compiled code for future page visits.
     
    xiangshushu, OceanX000 and De-Panther like this.
  4. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Hi jukka, when I refresh the browser again, it will not run faster. There is still a drop in frame rate at the beginning.
     
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,875
    We also see the same drops
     
  6. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    140
    Same issue here - reloading does not help.
     
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    The hypothesis here is that the Safari wasm compiler is a tiered compiler, which means that it will launch first in interpreted mode, and compile the wasm code on the background. Once the wasm functions each finish compiling, they will transition to the optimized faster versions, which improves performance.

    Unity 2021.2 is planned to bring a big optimization to WebGL compilation output, hopefully that can affect the performance curve for Safari.
     
  8. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Hi @jukka_j should I now check 2021.2.0a16? I saw the version of Emscripten not changed(1.38.11). Can we use simd128 flags in Unity 2021.2?
     
  9. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,067
    The optimizations haven't landed yet, sorry.
     
    mimiCryMuffin likes this.
  10. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    Most recent update after Schubkraft's previous entry is that the Emscripten 2021.2 is now looking very likely to have Emscripten 2.0.19 in it. We do see an improvement in startup times, build times, download sizes and runtime performance. Whether it will make the needed difference in Safari, that is hard to tell (we have not observed regressions in Safari at least).

    With the new compiler, there will be a backend to target Wasm SIMD128, although just flipping it on will probably not gain much benefit. For most parts, in WebGL builds we do not seem many workloads, except for skinning, which actually end up being a bottleneck that SIMD could improve. Though if you have your own native C/C++ plugin that does SIMD, that could certainly be optimized with targeting simd128.
     
    OceanX000 likes this.
  11. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Thank you very much for your reply and look forward to the official release of 2021.2。
    We are researching the method of webassembly for code separation. For example, record all the functions required during the startup phase as the first code package content. Reduce the pressure on downloading and compiling caused by too large code package.
     
  12. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    When testing in 2021.2, the following code seems to have no effect

    Code (CSharp):
    1.  PlayerSettings.WebGL.emscriptenArgs = "-s msimd128";
    2. BuildOptions option = BuildOptions.None;          
    3. BuildPipeline.BuildPlayer(GetScenePaths(), "webgl", BuildTarget.WebGL, option);
    I grep 'simd' in Folder WebGL/il2cppOutput/cpp and find nothing. Is there something wrong with me?
     
  13. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Unity2021.2 can reduce the amount of code, but it is not enough. A game with a code package of 30M when uncompressed requires nearly 50 seconds of JIT optimization time on iPhone7. Unity 2021.2 is difficult to significantly reduce the code size. Later, we tried to do wasm subcontracting by ourselves, and the situation would get better.
     
  14. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    679
    Any update on this?
     
  15. vadimtihonyuk

    vadimtihonyuk

    Joined:
    Feb 26, 2018
    Posts:
    32
    Bump, have similar problem on iOS 15 Safari, app loaded fast, but fps are very small, before was on 2020, but came on 2021.2 for texture compression
     
  16. GrzegorzBz

    GrzegorzBz

    Joined:
    Mar 28, 2020
    Posts:
    1
    Bump! Encountered same issue, both on iOS and Android devices.
    Tried 2020.3.17f1 (LTS) and 2021.2.1f1 versions.
    My 2D game is pretty small, but still game starts at framerate ~20 and after 15-30 seconds (depending on device) rises to 60. Tried to turn off almost all scripts, disable all coroutines and minimize gameobject count on scene, but in result initial fps raised to 40 recovering to 60 after same 15-30 seconds.
     
    mimiCryMuffin likes this.
  17. coldpizzapunk

    coldpizzapunk

    Joined:
    Aug 20, 2014
    Posts:
    30
    Bump using 2022.1.0b3 and I have found the same result. 30MB uncompressed file loads fine on Desktop, Android but on iPad I have 50 seconds of low framerates then it's fine. Wondering if there was any workaround anybody has found.
     
    mimiCryMuffin likes this.
  18. kritikos

    kritikos

    Joined:
    Aug 1, 2019
    Posts:
    5
    Hi, We are suffering from this issue too. It takes around 2 minutes on an iPhone X, to reach 60fps on our game. The uncompressed wasm code is around 34 MB in our case. Has anyone find any solution to this problem?
     
  19. Microph

    Microph

    Joined:
    Apr 9, 2016
    Posts:
    5
    any updates?