Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL build freezes after download large asset bundle through WWW

Discussion in 'Web' started by mstevenson, Mar 3, 2016.

  1. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    This is in regard to case 776348.

    When I download a large asset bundle by calling new WWW (url), the Unity WebGL player temporarily freezes immediately after the download finishes. Note that this is unrelated to loading the actual contents of the asset bundle into the scene, it occurs simply when the WWW request completes.

    Does anyone know a possible workaround? This is currently blocking our ability to port a large Web Player app to WebGL.

    Thanks!
     
    MFKJ likes this.
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    From the docs (http://docs.unity3d.com/Manual/webgl-building.html):

     
  3. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Jonas, Has there been any research done on using Web Workers and Transferable objects to handle these large network operations off the main thread?

    I havent done any experiments myself but I was wondering if Unity had dabbled in that at all.
     
  4. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    Thanks, Jonas. Though I don't see an option for LZ4 compression, does this need to be performed as a post-build step using an external tool?
     
  5. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    I spoke too soon, "chunk based compression" refers to LZ4. For anyone stumbling upon this thread, build your bundles as follows:

    Code (csharp):
    1. BuildPipeline.BuildAssetBundles ("Assets/StreamingAssets", BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.WebGL);
    This has increased our build size by 30%, but has reduced the load time to about 1/4 of a second, which I think is a fair trade.
     
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    LZ4 is a very different compression algorithm then LZMA (which would otherwise be used for your AssetBundles). LZ4 is optimized for speed, whereas LZMA gets better size. So your 30% size increase is expected. You can probably reduce size a bit by also enabling gzip compression for those files on the http server, so the files will be transferred gzip-compressed (on top of lz4).
     
  7. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Web Workers in the current state don't help much in the context of Unity as they don't map to any of our multi-threaded code which expects sharing memory between threads. This will become possible with the shared array buffer spec (which we have been experimenting with internally, see http://blogs.unity3d.com/2015/12/15/updated-webgl-benchmark-results/ ), but no browser is shipping this tech today.
     
    sirrus likes this.
  8. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    Jonas, is there any way to defer asset bundle decompression until it's explicitly triggered? There are a few places in our app flow where we could hide the decompression.
     
  9. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Unfortunately, no.
     
  10. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    Thanks, I was going to post this as a feature request, but is it due to lack of implementation in Unity or an inherent limitation of the browser?
     
  11. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    After disabling LZMA compression in webgl asset bundles, we need to implement it with custom downloader and compressor etc. which is imho counter-productive. We definitely need LZMA becouse of 2.5x better compression. Not 30%.
    Examples:
    Our binary file without compression = 604kb
    Packed AssetBundle for webgl (LZ4) = 103kb
    Packed AssetBundle for android (LZMA) = 43kb (2.5x better than LZ4)
    Packed manually with 7z LZMA/LZMA2 = 43kb
    Packed manually with rar = 50kb
    Uncompressed AssetBundle packed by GZIP in apache = 93kb
    Packed AssetBundle for webgl (LZ4) and then by GZIP in apache = 88kb
    other files have simular better income for LZMA.
    P.S. I must mention what we have many (100s) of 600k files (103k LZ4 or 43k LZMA) for better game update, not single 103kb assetBundle.
     
    Last edited: Nov 22, 2017
    MFKJ likes this.
  12. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I am getting the same issue, after downloading the asset bundle using unitywebrequest my webgl freeze for 2 to 3 minutes. I am using compression less bundles as i found that asset bundles without compression work quickly. Even i tried asset bundles with chunk based compression but the problem still persist.
     
  13. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    The webgl freeze and producing great amount of lag (around 40 seconds) after loading the asset bundle. I have tried both asset bundles (compress, non compress) but still the problem same. I know that webgl is single thread but why it freeze after loading the asset bundle. And the build working fine in editor. Hope that unity webgl editor is also on single thread to replicate the real environment.