Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Smallest possible WebGL build size?

Discussion in 'Web' started by AdamandEveStudios, May 5, 2023.

  1. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Has anyone ever tested this? For arguments sake lets say there are zero assets in the project. One simple scene being built with nothing except a camera and directional light. With the highest compression and stripping what would the smallest possible webgl size be?

    Have optimized every single asset dowe to the kilobyte but am left with huge UnityEngine DLLs clogging up the build. Current build size is 18MB and System DLLs, Script DLLs, and UnityEngine take about 12MB.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Be sure to check RELEASE builds only!

    My last WebGL build was less than 10 MB and ~5 MB is supposedly (read that in some other thread) about as low as you can go - but this changes between Unity versions.

    UPDATE: I investigated minimum WebGL build sizes here (1.8 MB for Legacy, 3.5 MB for URP). That thread contains a lot of other useful info as well.
     
    Last edited: Jun 18, 2023
    1000Nettles likes this.
  3. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    thank you for the reply. ~5 MB is definitely the goal. Good to know that this is actually achievable. By release mode do you mean not developer mode? I rarely use developer mode when building to webgl.

    In terms of Unity versions I just made the fatal error of upgrading to 2022.2.17 and now all my webgl builds hang permanently on "linking build.js" :(
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    830
    The smallest build I achieved was 2.47MB with Unity 2020.3 with builtin render pipeline and brotli compression targeting webgl1. This build includes a simple test scene with some falling blocks and I also didn't start manually stripping out builtin packages, so I think you can go een a bit lower than that. You can test the build yourself here: https://deml.io/experiments/unity-webgl/2020.3.46f1-minsize-webgl1
    And that is the repo to see the exact setup I'm using: https://github.com/JohannesDeml/UnityWebGL-LoadingTest
    To get the settings for the min size build, just build the project with minsize, then it will apply all settings that are used for that to the project settings :)

    upload_2023-5-5_19-25-48.png
     
    LilGames, Wokou-Dev and Unifikation like this.
  5. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Wow. This is exactly what I needed. Truly amazing info you've gathered all into one nice spot. I will use this and report back!

    In terms of build size for webgl 2 - 2021.2.19f1 is the winner? I will be porting over my project to a stable version as 2022 is basically unusable
     
  6. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    830
    Glad you find it useful!
    Yes, that would be the winner, but tbh I would recommend to go with Unity 2021.3.x, since that is the LTS version, and the difference in build size is not that big. If you want to see and test all the builds I did over the years, you can find them here: https://deml.io/experiments/unity-webgl/
    Note however, that the unity template and functionality grew a bit over time, so older build versions might have less KB. The list of builds on the github page is a fair comparison, since they all use the same template.
     
    Wokou-Dev and Unifikation like this.
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Regarding release, check the player settings. You want to tick all the release buttons, disable exceptions and all that.
    However for development you should definitely make debug/dev builds because they can be done in 2 min. vs 20 for a release build. Check what the build time is for your project in dev vs release builds, and do each build twice so you can see the truly incremental build speedups.

    As to upgrading and running into troubles, my experience is that you are most likely have to debug the issue. It’s comparatively rare that it’s a specific Unity issue and waiting will get it fixed. In any case, try 2022.2.0 and see if it works there. If it does you can work your way up to the highest version that still builds your project, then check the changelogs for the next version for any hints regarding what may trigger the issue.
     
  8. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    this is an absolute gold mine of information. Should be pinned at the top. TY for making this
     
  9. sidney7111

    sidney7111

    Joined:
    Jun 28, 2020
    Posts:
    10
    This guy is right, I followed his project and packed success as a 3.5Mb build .apk or folder(no need webgl, or URP), I wonder who said URP is small first; The logic is if URP is small, then built-in is no need to exist(It's nothing about render & graph) ; Besides, 99.9% information in forum will tell you compress, compress, yes it work if you could compress a png file. but you ever done it and you konw how to compress pixeles with code? if not, you dont have any concept of compression of digital Asset, so please dont trust someone who want to teach you compress, you have to learn CS for your own
     
  10. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Note that with Unity 6 Preview you can disable the splashscreen logo which will remove a couple KB. As well as what I did, specifically disabling unused built-in packages can remove several hundred KB.

    Also compression is about more than PNG files and build compression will lead to a smaller build - it only depends on the assets in the project as to how much compression can be achieved.
     
  11. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Huh????? If you don't know how to compress assets in your project with the default unity options you are in for a very rude awakening. Like @CodeSmile said, 95% of reducing build size is the simply compressing textures and meshes with unity's default options (even though there is still some confusion as to whether crunch compressed textures reduce the texture size in both disk space AND memory space or solely disk space) Example crunch compressing a 4096x4096 png to 128x128 only reduces file size and not memory. Lot of conflicting tests and unity docs all have inconsistent info. Other obvious benefit of crunching is the huge load time performance increase. Great info from bgolus in this thread: https://forum.unity.com/threads/why-use-crunch-compression.581986/

    URP builds will evidently be slightly larger than BIRP builds because of all the package requirements like shader graph / mathematics / burst etc. The tradeoff is around ~2MB and you get all the benefits of URP on web. Not sure who told you URP can be smaller size than BIRP that's just blatantly false info.
     
  12. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    The packages actually (typically) contribute little to build size, unless they contain larger assets. From what I recall the majority of size increase of URP is due to materials and corresponding textures and shaders included in the URP and/or SRP packages.
     
    ilmario likes this.
  13. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Shader graph + Core RP library adds something like ~1.1MB if I recall correctly. TONS of prefabs from core RP package alone that get forced into build that include textures and debug ui nonsense. I mean I would gladly spend the time manually editing these packages but its kind of waste when unity just pushes new LTS is actually a giant step backwards and increases build size lol.
     
  14. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    But hey we're talking about +2 Mb tops. And nobody has done any measurements as to whether this actually increases load time, which would be the primary (only?) concern. If these assets exist in the build but aren't used and thus not loaded I would expect them not to affect the load time.
     
  15. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Very true. At some point the time spent trying to decrease build size becomes counter productive, especially when your sifting through literal kbs of tiny insignificant files.

    I think it comes down to sunk cost fallacy where you know you've already invested so much time keeping build size as small as possible, that skimping out at the end (however insignificant + tiny the size is like 2MB) seems like destroying all the previous work optimizing. Also if your final build size is like 6MB, those forced 2MB are now 30% off entire build. You spend all this time reducing and cleaning the size and then unity just takes a fat dump all over it at the end.

    Or it's just a mindset of not wanting unity forcing their disorganized fluff into pristine clean projects. Especially when the packages are mandatory and a pain / impossible to manually remove. But this also doesn't make sense when you think about it because the entire engine itself is horrendously optimized and most likely filled to brim with unnecessary resources...

    Also at this point, everyone has blazing internet / good enough phones that those added MB are quite literally negligible for download and load time.

    It's always funny to read these forum posts and see the vast differences in people's final build sizes. Majority will have like 10-20MB builds but then some newbie will proudly proclaim how they got build down to like 250MB. (I don't even want to know what % of that is solely textures or how long that build even takes to load in browser) It's a huge learning curve which is somewhat ironic because I was that newbie seeking knowledge when I wrote this original thread over a year ago. In those 12 months I've done well over 10,000+ web builds and still haven't come to final conclusion on what the "Smallest possible WebGL build size" is or will ever be :eek::eek::eek:
     
    CodeSmile likes this.