Search Unity

Build AssetBundle: why is it SO SLOW

Discussion in 'Editor & General Support' started by NoobCoderFake, Jan 4, 2019.

  1. NoobCoderFake

    NoobCoderFake

    Joined:
    Nov 24, 2015
    Posts:
    42
    1546584047549.png
    It calls 3000000+ times and 1.18GB GC alloced, freeze UnityEditor for more than 20 seconds.
    Why is it so slow? Anything not optimized carefully in BuildPipeline?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    From my experience, it depends on the asset bundle setup.

    In order to improve build times, we split content into several bundles. For example, rather than having very few bundles that contain "everything" we have many smaller bundles for textures, audio, scenes, materials, shaders, and so on.

    Bundles are then further split. Rather than having one bundle for all textures, we have a separate texture bundle for each character. The same applies to audio, etc. Basically all of these larger file types are split into several bundles. We also store one scene per bundle only.

    This allows Unity to only rebuild the bundles where assets have changed since the last build, causing a significant improvement in build times.

    For example, if we change the "Monkey" texture, Unity only needs to rebuild that one bundle where that monkey texture is stored in, which completes in a very short amount of time.

    The very first "BuildAssetBundles" call still takes a significant amount of time, but subsequent builds are very fast.


    If you already use such setup, you probably should post more details to allow us to help.
     
  3. NoobCoderFake

    NoobCoderFake

    Joined:
    Nov 24, 2015
    Posts:
    42
    Thanks for your reply.
    I've separate assetbundles to very small size, each bundle only contains less than 5 files.
    This happend when I've built about 400+ bundles, and then I changed some of them, build assetbundles again to get those changed files into my StreamingAssets folder. What I've changed is just one or two text files, do not dependent any other resources, so there's no need to process dependencies or any other thing.
    As deferent platform need deferent setting of AssetBundles, I store those infos (for each file, what AssetBundle name it should to be set) into a cheet, and call
    Code (CSharp):
    1. public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform);
    to start a build.
    As I know which file has been changed, I only post those changed AssetBundles into {AssetBundleBuild[] builds}. Is that a problem?
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Maybe that's the issue. We use BuildPipeline.BuildAssetBundles and let Unity figure out what has changed and what needs to be rebuild. Can you give this a try and check if it makes a difference (the first build then probably takes a while again)?

    PS: Changing platform and rebuilding bundles builds pretty much everything again as far as I could observe/guess. I often use different checkouts for different platforms to workaround "this issue".
     
  5. NoobCoderFake

    NoobCoderFake

    Joined:
    Nov 24, 2015
    Posts:
    42
    We couldn't use BuildPipeline.BuildAssetBundles for a reason: we don't want to build all changes into AssetBundle, but only those we need to. Mostly we develop other things and build a hotfix to fix a online bug, in the same branch (we use SVN for version controll). So there are changes for new things we are still working on, and changs for hotfix we need to build and post online.

    Maybe it's a pain we need to endure……
    And thanks for your kind help.
     
  6. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    It doesn't mather much if the asset bundles are large or small. While building these bundles i can't do much on my workstation (threadripper 16cores, 32gig ram). Unity uses just 1 core or so to build, but the system gets laggy anyway. No chance to work inbetween in maya, even that there is plenty of ram and processor power left. The bundles are saved out on ssd.

    We use it as well like this. Problem is: Unity is really bad in figuring out what has changed and what not has changed. Often times it rebuilds unneccessarily everything (!), even when nothing has changed except one little change in one asset bundle. (it's version controlled by git: even git sees non of those "changes", except the one expected)

    Ohh, this could be an idea. We build win, osx and webgl bundles in series in their plattform specific folders.
    When unity rebuilds everything, then only the "win"-asset bundles. i have never seen that it rebuilds unneccessarily the "osx" and "webgl" asset bundles. (everything is build on the windows machine)
     
    Peter77 likes this.
  7. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    107
    Not sure if this is applicable, but I believe I have seen shader variants take a while to process. Maybe your asset bundles are using non-standard shaders?
     
  8. yuhuilalala

    yuhuilalala

    Joined:
    Nov 8, 2014
    Posts:
    7
    My mmo test project cost 7 hours for AssetBundles .....
    How could this be ....