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

Optimized WebGL Load Times

Discussion in 'WebGL' started by Dan_NextRevC, Sep 12, 2018.

  1. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    Empty WebGL scene loading times, there is absolutely nothing running in the scene, just wanted to describe how I got fast loading times.

    Try It For Yourself

    Desktop
    Safari: ~3s
    Firefox: ~1.5s
    Chrome 69: ~2s (faster due to new JS Engine)
    Chrome 68: ~6s

    Mobile
    Had some issues with reloading the webpage though, could be missing a package
    Chrome: ~5-6
    Safari: ~5-6

    Project Setup:

    Build Size: 3mb

    2018.2.7f1
    Data Cache Enabled
    Enable Exceptions: None
    .Net 2.0 Subset
    .Net 3.5 Equivilent
    Gzip
    WebAssembly

    Unity Packages:
    • Asset Bundle
    • Audio
    • Physics
    • UI
    • UI Elements
    • Unity Web Request
    • Unity Web Request Audio
    • Unity Web Request Asset Bundle
    • Unity Web Request Texture
    • Unity Web Request WWW
    • Video (possibly required to run on mobile)
    The rest of the Unity Packages have been disabled for optimization using Package Manager
    Further optimizations could be done but that involves work on the build pipeline.
     
    Last edited: Jan 11, 2019
    Fenikkel, blueivy and JamesArndt like this.
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Next week there will be a blog post on this topic.

    Out of curiosity, which mobile device have you tested?
     
  3. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    I'm really excited to see that blog post! Here is a list of phones we quickly tested on:
    • iPhone 6s
    • iPhone 7
    • iPhone X
    • Pixel 2
    It seems like it would work on any modern phone.
     
    Last edited: Sep 14, 2018
  4. vb2s360

    vb2s360

    Joined:
    Oct 7, 2015
    Posts:
    33
    Amazing. Thanks for the post.
     
    MKaraman likes this.
  5. rhamoud

    rhamoud

    Joined:
    May 20, 2013
    Posts:
    18
    Just Wow! I was able to take my current project with load times of 25+ seconds and knock it down to a very quick 6 second load time. Thanks for the share!!
     
  6. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    @Dan_NextRevC great post!

    Question: why Gzip? It is my understanding that Brotli brings down size even more...
     
    Last edited: Sep 20, 2018
  7. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    I just tested Brotli vs Gzip for one of my projects.

    Brotli: 6.36Mb
    Gzip: 8.12Mb
     
  8. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    @Marco-Trivellato I saw that you posted last week about a blog post coming this week. Is that published yet?
     
  9. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    mattbrandmm likes this.
  10. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    @mattbrandmm Gzip is supported on all browsers whereas Brotli doesn't support Safari, so I wanted to have consistency for all of the tests.
     
  11. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Safari supports Brotli if you use macOS 10.13 or later (also iOS supports it).
     
  12. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Isn't there also gzip and brotli JS decompressors embedded in the UnityLoader.js in case of missing browser support? It's obviously going to be slower but it'd resolve compatibility issues (in theory).
     
  13. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    Wow you guys are really for the brotli compression huh. I didn't know Safari supported it, and that's really cool thanks for sharing! My company will probably be using gzip until MacOS 10.13 is at-least at 75% market share (currently 53% for High Sierra). Or do some speed testing with brotli on MacOS < 10.13, might recommend them to just bypass that all together if @JJJohan you're correct. Super helpful insight guys, I'm glad I could start a forum like this!

    Brotli = ~2.5 mb
    GZip = ~3.2 mb
     
  14. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    555
    Nice test.
    How do you count the time?
    From when the page loads, or when the download bar stops?

    Also, how did you test it on iOS if it uses WebAssembly? Didn't apple remove the support for WebAssembly on iOS for some security issues?
     
  15. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    yes, the UnityLoader comes with decompressor fallbacks.
     
  16. frankadoriv

    frankadoriv

    Joined:
    Jul 19, 2017
    Posts:
    14
    Results made today using the provided link:

    Chrome v70: 8~9s
    Canary v72: 2~4s
    Firefox: 2s

    MacBook Air
    1.8 GHz Intel Core i5
    8 GB 1600 MHz DDR3
    macOS: 10.13.4

    Something can be tuned on the browser side on Chromium 69?
    I have an application made with Unity 2018.2.12f1 running on Electron 4 with that version but i cant reach less than
    8 seconds of load with an empty project.

    Maybe building Electron against Canary but... is a very heavy process.
     
  17. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    The exact chrome browser version I was using was 69.0.3497.100 (Official Build) (64-bit) 69.0.3497.100 (Official Build) (64-bit). I just updated and saw similar loading times in a fresh incognito window, meaning around 2-3s, not the 8-9 that you saw. It could be that I have a better machine, I have a MacBook Pro 2018. I can't speak much to Electron, as I have only touched on that technology a little bit, but do make sure that you are stripping out as many packages you can through the package manager.
     
  18. frankadoriv

    frankadoriv

    Joined:
    Jul 19, 2017
    Posts:
    14
    Wow! On incognito windows load fast. I have only one window in the main account and is slow, mmm what could be the difference...
     
  19. Dan_NextRevC

    Dan_NextRevC

    Joined:
    Apr 18, 2018
    Posts:
    19
    Probably you had a large cache or something with your browser, I haven't seen loading times that slow for this project ever, I don't know why it was loading that slowly. Maybe something to look into.
     
  20. healthplexus

    healthplexus

    Joined:
    Aug 18, 2017
    Posts:
    2
    Hi, We have a presentation with a few pages before WebGL page starts that user is going through, so we would like to initiate download and caching of the large App.data.unityweb file while on the very 1st page of that presentation. Unity WebGL doc: "Data caching Enable this option to automatically cache your contents Asset data on the user’s machine so it doesn’t have to be re-downloaded on subsequent runs." And it is working after the 1st run. Is it possible for WebGL to cache Data App.data.unityweb before the first run?

    Thanks a lot!
     
  21. dzynek

    dzynek

    Joined:
    Jan 20, 2016
    Posts:
    3
    I have 30Mb/s internet:
    Xiaomi Redmi Note 5 - Android 9 - Chrome: first time 10s next 7s, 8s. Firefox: first time 9s next 4s, 3s
    Ipad Air 2 - Ios 13.3 - Safari: first time 8s next stopped loading, 5s, stopped loading, Chrome similarl :(

    Armory3D (beta) - free addon for Blender - Simple Puzzle3D Demo
    http://dzynek.pl/games/test_demo_puzzle3d/

    Load faster, automatic server-side compression.

    It can be used for simple games, has Visual Script.
    Armory Mode: Render Mobile - Legacy Shader only simple Difuse Material and one Light but works everywhere, in the future it may be interesting.
     

    Attached Files:

  22. obeycmb

    obeycmb

    Joined:
    Feb 16, 2021
    Posts:
    2
    Thank you so much! This solved my problem with lag during runtime as well.
     
  23. warrenLD

    warrenLD

    Joined:
    Jul 2, 2019
    Posts:
    9
    Wait, coming to this thread late and looking for solutions to cut down on build size/initial loading times, does having a lot of Unity Packages in your project, even though you're not using them exacerbate load times?
     
  24. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    18
    anyone care to make an updated May 2023 edition of this thread :):):)