Search Unity

Which Code Optimization option is standard?

Discussion in 'Web' started by brodiebrodie, Jan 14, 2022.

  1. brodiebrodie

    brodiebrodie

    Joined:
    May 21, 2018
    Posts:
    6
    I can choose between Size and Speed for "Code Optimization" in WebGL build.

    What exactly is this referring to? Is "Speed" simply the time it takes to compile? If so, for production builds you should always select "Size", correct?

    Screen Shot 2022-01-13 at 11.38.23 PM.png
     
    Last edited: Jan 14, 2022
  2. DannyWebbie

    DannyWebbie

    Joined:
    Jun 5, 2018
    Posts:
    7
    This is covered in the documentation: https://docs.unity3d.com/2022.1/Documentation/Manual/webgl-building.html

    Code Optimization Select the optimization mode to use for compiling the WebGL code.
    Speed This is the default setting. Selecting this generates WebGL code that is optimized for runtime performance.
    Size Selecting this generates WebGL code that is optimized for build size. This is particularly useful when building WebGL games to run on mobile browsers on Android and iOS, where the default optimize-for-speed option would generate larger WebAssembly files for mobile devices to consume.
     
    Fenikkel, russisunni and brodiebrodie like this.
  3. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    340
    Does anyone have some stats on how slower a code optimized for size might be ? I understand it is correlated to the use of generics, and whether the app is CPU bound or not, but it would be great to have a ballpark estimate of what we are talking about here
     
    LilGames, Fenikkel and xiangshushu like this.
  4. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    397
    Can anyone answer the question of @unisip ?
    In the latest Unity versions the "Shorter Build Time" was added.

    So far when I test the different options my results are:
    • shorter build time - the build time is reduced from 1,5 hours to about 15 minutes
    • runtime speed - I see no change in performance
    • disk size - The build is reduced from 100MB to 70 or something like that
    the loading time is the same in all options and I also did not experience a change in performance.
    So what does "runtime speed" do?
     
    GDevTeam likes this.
  5. Ali-Unity3D

    Ali-Unity3D

    Unity Technologies

    Joined:
    Mar 8, 2021
    Posts:
    23
    Historically, before the option was introduced, optimising for speed was always the default behaviour, with the exception of when doing a Development build. Speed refers to the runtime execution speed of the code. Size refers to the amount of code the build produces.

    Code Optimization Size (-Os) / Speed (-O3) essentially boils down to a flag that's passed to the compiler and the linker, in case of the compiler, it controls things such as
    https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

    In practice it might be difficult to notice any runtime performance differences without doing very detailed profiling for the code, but the effect on the size reduction should be typically quite clear.

    The option for shorter build time is a new one, I'm not that familiar with it, I'll have to get back you on that.
     
    Last edited: May 26, 2023
  6. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    397
    Thx for the information.

    Since Unity 2022.2, the "linking" phase of the build process needs a lot of time, for my apps 1,5 to 2 hours.
    With "Shorter Build time" the time is decreased to the level of Unity 2022.1 (< 15 minutes).