Search Unity

What compression should we be using for WebGL Asset Bundles?

Discussion in 'Web' started by kognito1, Aug 30, 2016.

  1. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    So I was reading the 5.5 beta change log and I found an interesting tidbit:

    Uh what? This is certainly news to me. I've always been under the impression that for downloads (WWW/UnityWebRequest) you want to use lzma (for smaller files) and only use lz4 if you are loading the bundles locally (LoadFromFile).

    I'm guessing you want us to use chunk compression (lz4)? Where was this previously "discouraged"? Can you add this information to https://docs.unity3d.com/Manual/AssetBundleCompression.html? The "best practices" for asset bundles are not clear for WebGL.
     
  2. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
  3. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Ah that's what they were referencing? But why take this option away if it's just the performance loading issue we've always had? Just make it crystal clear in the documentation the ramifications of compressed bundles. I was worried they were referencing some runtime cost that I was unaware of.

    So sadly this negatively impacts us. We split our applications into like 50 asset bundles and load them behind a javascript/html loader (i.e. we hide the unity webgl content while it's loading the application/bundles). Thus this "feature" does nothing for us other than increase our sever and transportation costs. :(

    I don't get the logic behind removing a perfectly functioning feature in order to combat ignorance...
     
  4. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    We deal with many (hundreds, potentially thousands) of assetbundles per game session so it impacts us as well.

    Our pipeline is such, however, that we can pretty easily redeploy uncompressed assetbundles. BUT, Unity mentions that gzip compression makes sense for WebGL-targeted assetbundles. Why not simply include gzip as a compression option when building assetbundles then? And I agree, even if LZMA is inefficient, if it's not flat-out broken why break a great deal of compatibility with existing projects?

    We've tested some manual gzip compression (our CDN host doesnt offer gzip compression automatically) without any luck so far. Still looking into it.
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Actually my recommendation would be to use LZ4 compression on AssetBundles (which Unity will now do when you try to build an LZMA compressed AssetBundle), and, if you need smaller size, compress that using Gzip or Brotli. This gives you the best compromise in download size, loading times and in-memory size.

    As for why removing LZMA support in Unity completely: The problem is that it is the default setting in Unity, but it is very inefficient for using in WebGL (actually, I think LZMA is also outperformed by other algorithms in general, and should probably be completely replaced in Unity, but that is a different story, which we will probably look into in some point in the future). As long as it is the default, people will default to using it, creating sub-standard experiences in UnityWebGL. Furthermore, we don't need to carry around the LZMA decompression code in Unity WebGL any more if we just disable it.

    As for "Why not simply include gzip as a compression option when building assetbundles then?". We will probably do that at some point, similar to what we do with the main player data, where we supply a fallback for servers not configured correctly to handle compression.
     
  6. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Jonas,

    Does this mean that the 'best practices' documentation for Assetbundles referenced above is out-of-date (due to 5.5) or simply incorrect in terms of compression suggestions?
     
  7. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    It could be either (not sure if LZ4 compression was around when it was written). I will find out who is responsible for maintaining that and get it fixed. Thanks for reporting this.
     
  8. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Thanks @jonas-echterhoff for the explanation. I can live with LZ4 compression. And thanks for trying to update the documentation, it wasn't very clear what the optimal settings were for webgl.
     
  9. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    Does the slowness of LZMA de-compression under webgl out-weigh the much bigger download size of the assetbundles with LZ4 compression then?
    Also can anyone give a brief explanation of how you serve them with gzip compression?
     
  10. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
  11. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    Sorry for bumping back this thread but I am having similar problems and would like some advise...

    We deploy on both Standalone and Webgl and the difference is literally the double of the size for WebGL.

    Our users are bandwidth dependent and we can't force server-side compression such as gzip. Lastly, our building is highly automated with custom scripts, so we don't use the default publishing menu at all, limiting us with the post-build compression of Unity (such as gzip if ever we find a way to use it).

    Any suggestions?
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    is the size of webgl asset bundles double compared to Standalone? What Asset bundle compression are you using?
     
  13. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    It's 77% bigger; one exemple standalone bundle is ~40mb, vs the WebGL version is ~71mb. We have multiple assetbundles.

    Bundle compression is LZ4 (BuildAssetBundleOptions.ChunkBasedCompression) as per documentation.

    Something we noticed, I don't know if it's particular or not, is that according to the Editor Log;

    (Standalone):

    Compressed Size:40.2 mb
    Uncompressed usage by category:
    Textures 71.2 mb 45.2%
    Meshes 24.6 mb 15.6%
    Animations 2.1 kb 0.0%
    Sounds 0.0 kb 0.0%
    Shaders 1.2 mb 0.8%
    Other Assets 327.1 kb 0.2%
    Levels 59.9 mb 38.1%
    Scripts 2.2 kb 0.0%
    Included DLLs 0.0 kb 0.0%
    File headers 98.5 kb 0.1%
    Complete size 157.3 mb 100.0%


    (WebgL):

    Compressed Size:71.1 mb
    Uncompressed usage by category:
    Textures 71.2 mb 41.2%
    Meshes 24.6 mb 14.3%
    Animations 2.1 kb 0.0%
    Sounds 0.0 kb 0.0%
    Shaders 2.1 mb 1.2%
    Other Assets 327.1 kb 0.2%
    Levels 74.2 mb 43.0%
    Scripts 2.2 kb 0.0%
    Included DLLs 0.0 kb 0.0%
    File headers 98.5 kb 0.1%
    Complete size 172.5 mb 100.0%


    Notice the "Levels", it's 15mb bigger. It accounts for the biggest delta between both export options.
     
    Last edited: Jul 12, 2018
  14. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I think the two platforms differ because Standalone bundles are likely compressed with LZMA.

    could you please elaborate more "we can't force server-side compression such as gzip." ?
    that is actually what I would suggest to do...
     
  15. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    We deploy our web-based version of our product on our clients LMSs, for which we do not control the server configuration. Additionally, as our products are not games, the production environments are more tightly controlled (security, stable configs, etc). Wasn't a problem with the old web player and when our projects were smaller but now we are having trouble delivering our mandates without re-scoping down even more for WebGL. It really hampers our development efforts.

    Is there any way to get LZMA back for WebGL, or any other alternatives?
     
  16. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    You don't want LZMA...you want Unity to give us the ability to compress (WebGL) bundles with gzip or brotli so the browser can handle decompression. :)
     
    CodeBear likes this.
  17. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
  18. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Amusingly we just switched off LZ4 last week as we finally migrated all of our webgl bundles to be uncompressed + gzip! Makes a huge difference on slow (Android...) devices. :) However prior to that we had no issues with LZ4. Here's our old build options (nothing too crazy):

    Code (CSharp):
    1. BuildAssetBundleOptions options = (BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DisableLoadAssetByFileName | BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension);
     
  19. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Can anyone tell me how to compress my asset bundle with gzip? Currently, i am using asset bundle browser and there are three compression types in it:
    1 No Compression,
    2. LZ4 (LZ4 is right choice for webgl)?
    3. LZMA (LZMA is obselete according to this thread?)

    I am using Unity 2019 with Webgl build. Thanks
     
  20. Eckster

    Eckster

    Joined:
    Feb 9, 2017
    Posts:
    18

    The idea is that you enable gzip compression on your web host, typically using Nginx or Apache, alternatively you gzip it yourself and configure them to use the gzip'd version if a request comes in that can accept it.