Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Empty webgl project over 10MB uncompressed

Discussion in 'Web' started by Marks4, Jun 2, 2021.

  1. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    516
    You see this post is from 7 years ago. The output folder of an uncompressed webgl build with an empty scene is still 14MB. Surely this can be improved right? For comparison with brotli compression it's 2.51MB. It would be nice to bring down this 14MB below 10MB.
     
    Last edited: Jun 2, 2021
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    At that time Ralph and Jonas were heading the WebGL team. They did a lot of work on modularizing Unity to the architecture it is today. It is not something that we would be neglecting. In fact, this is one of the biggest challenges that Unity export faces today, and we are well aware it is the main selling point that competitors advertise themselves over Unity.

    Optimizing this turns out to be exceedingly hard without making tradeoffs. When the number of users is at the tens of thousands, making tradeoffs to the status quo is considered more and more unacceptable, since it can break a lot of users. Dead Code Elimination ("tree shaking" in JS parlance) can get one only so far, and we are now looking at next generation avenues towards eliminating code size further.

    When Unity 2021.2 Beta hits, try out the empty scene again in a size optimized build - I think it should then be below the 2MB mark as .br by default. We do have a roadmap and both active research and develop-to-production items in flight towards optimizing this size down further - we want to hit empty scene below the 1MB mark compressed.
     
    sama-van, GCatz and adamgolden like this.
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Check your editor log (console window top right menu gadget -> Editor Log) after a build it will provide a breakdown of all of the things in the build before compression e.g.

    You may find a lot of elements dragged into your project that are not used but in default packages or samples.
     
    _watcher_ and De-Panther like this.
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Just tried an empty scene WebGL build in 2021.2.0a17 and got this Build report

    3.3 mb (gzip compression)

    With Code Optimisation for Size and Faster Smaller build options

    2.9 mb (gzip)

    2.2 mb (brotli)
     
    Last edited: Jun 2, 2021
    De-Panther likes this.
  5. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    After removing all packages via the package manager:

    2.2 mb (brotli)

    Note that the Total user assets is down to 15.6 kb so the remainder is the default Unity WebGL base.

    On a side note you can try Tiny which is designed to build very small WebGL builds.

    @Unity it looks like the script stripping for unused packages or scrips is not working.
     
    KamilCSPS likes this.
  6. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    431
    Good analysis, thank you! Can you bug-report the package script stripping issue?
     
  7. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Maybe when 2021.2 hits beta, it would be better?
     
  8. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Testing an empty scene build through the upcoming Unity 2021.2 Beta branch, with "Code Optimization: Size" and "IL2CPP Code generation: Faster (smaller) builds",

    .wasm.br: 1,482KB
    .wasm.gz: 1,931KB
    .wasm uncompressed: 5,380KB

    Indeed like KamilDA mentions, would be good to acquire a bug report about the package stripping issue.
     
  9. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    516
    You need a bug report for this, or is it under your radar to fix it already for the next version? 5.4MB uncompressed vs 14MB before. That's a huge difference. Can't wait to market using Unity for webgl saying that it went down from 14MB to 5.4MB, super light now!
     
  10. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    It's great for an empty project, but my experience with an existing project is the opposite:

    All the sizes are after GZIP.

    Unity 2020.2.6f1 code optimized for speed build:
    WASM 4.72 MB
    Data 6.69 MB

    Unity 2020.2.6f1 code optimized for size build:
    WASM 3.78 MB
    Data 6.69 MB

    Unity 2020.3.11f1 code optimized for speed build:
    WASM 4.79 MB
    Data 6.68 MB

    Unity 2021.2.0a19 code optimized for speed build:
    WASM 5.80 MB
    Data 6.95 MB

    Unity 2021.2.0a19 code optimized for speed, IL2CPP code generation smaller build:
    WASM 5.52 MB
    Data 6.94 MB

    Unity 2021.2.0a19 code optimized for size, IL2CPP code generation smaller build:
    WASM 4.44 MB
    Data 6.94 MB

    I only upgraded the project by opening it in different Unity versions, didn't add packages by myself and didn't remove any. There were some packages that auto updated, and maybe Unity added some new ones.

    What makes the end WASM files larger in each version?
    What made that jump in size for the data file using 2021?
    Maybe there are some size optimization tips relevant to 2021?

    It's weird, the same assets in 2020.2 are 6.69 MB (6853 KB) and in 2021.2 are 6.94 MB (7115 KB).

    I prefer not to use the "code optimized for size" as it affects the performance.
    But WASM size of 4.72 MB in 2020.2 vs the WASM size of 5.80 MB in 2021.2, more than 1 MB, it's a lot.
     
  11. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Check the editor log (via console menu) it does a build report detailing what goes into each build and will let you see any differences between builds.
     
  12. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    I know about that, that's how I optimized most of the size in the first place.

    That doesn't answering my questions :)
     
  13. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Check the differences between the Build reports for the Unity 2020.3.11f1 and Unity 2021.2.0a19 builds.

    If there are no differences in the included user assets then it has to be in the Unity core data/code or the compression techniques.
     
  14. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    And this is why it isn't answering my questions. :)

    That could have been a solution, if there was no code stripping, but there is code stripping(and the build report have a list of files that were used, not what stripped from them or if they were stripped),
    so even comparing the scripts files that were added(can't check like that methods and variables that were added to existing files),

    it won't answer my questions:

    What makes the end WASM files larger in each version?
    What made that jump in size for the data file using 2021?
    Maybe there are some size optimization tips relevant to 2021?
     
  15. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    The tool that can give more info than the editor log, is
    https://docs.unity3d.com/ScriptReference/Build.Reporting.BuildReport.html

    But even this tool, while can provide data on changes in packages, won't provide data on the IL2CPP backend changes, and won't provide data about new settings or changes in settings for assets.

    As I saw a comment about ASTC textures support in WebGL, I'm guessing that there's a related setting for it, and that it might affect the data file size
     
    OceanX000 likes this.
  16. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    820
    Last edited: Jun 8, 2021
  17. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    @Johannski Thanks a lot!! Your work ss very useful
     
  18. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
  19. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    820
  20. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    820
    Okay, back home and managed to create a build with the new beta: https://deml.io/experiments/unity-webgl/2021.2.0b1/

    Here some notes:
    • I needed to change folder permissions inside the new unity version to build the project (more information)
    • There has been some changes to Unity's variables and javascript functions that I needed to adapt to (commit)
    • Build size got about 200 KB smaller comapred to 2021.1.0f1. However, note that this project is not using any audio or textures, so I expect a lot more noticable improvements for larger projects.
    • Build times improved quite a bit for me :)
    • I got an error for building with min size settings with disabled exceptions. Bug report already sent (Case 1346348).
    Github release
     
    Last edited: Jun 28, 2021
    _watcher_, OceanX000 and De-Panther like this.
  21. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    516
    Here we are on Unity 2021.2 and an empty project is like 20MB. Why? Just, why?
     
  22. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    820
    If you use e.g. brotli compression this is far from true. You can get an empty build down to 2.5 MB and less. I made a detailed comparison for different unity version over the years: https://github.com/JohannesDeml/UnityWebGL-LoadingTest

    Where do you see the 20MB empty projects? Is it uncompressed + URP / HDRP? What do you want to achieve?
     
    CrandellWS likes this.
  23. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    516
    Not talking about compressed projects. Uncompressed ones. SRP. Why does an uncompressed project weight 20MB? There's nothing. Why is nothing 20MB?
     
  24. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    431
    Well, if you go to the build report you'll see why. Nothing doesn't mean no UI, no Rendering, no Memory... no Engine.

    That 20MB is the Unity Engine.

    Albeit, I agree its still waaay too heavy.
     
    Marks4 likes this.
  25. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    KamilCSPS likes this.