Search Unity

Very long processing time on "Write Serialized Files" when building assetbundles without changes

Discussion in 'Asset Bundles' started by Kichang-Kim, Oct 17, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Hi. I used Unity 2019.2.9f1 + ScriptableBuildPipeline 1.5.2 for building assetbundles.

    But I found that even the source assets are not changed, "Write Serialized Files" takes very long time.

    Output assetbundle's CRC and modification time is not changed, so I think that final result may be copied from cache, but why "Write Serialized Files" takes long processing time?

    (Archive and Compression process ended very quickly)

    It seems that this issue is occurred only with large scene data (output assetbundle size is bigger than 50MB).

    Is this bug or intended behaviour?

    Thanks.
     
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Because of this issue, my assetbundle build time is longer than player build (include all assets).

    Player with all assets : ~30min
    Assetbundles (subset of assets) : ~90min
     
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    I have found some bugs regarding this. One of them is here. Unfortunately, I have not been able to submit a format bug for it before now, because I have not been able to reproduce it outside our main project, but I may be able to do so soon. Another thing I found is that Write Serialized Files takes significantly longer if you trigger a build with a scene open. Not entirely sure why.
     
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Hi, Thanks for sharing issue. I figured out my case and reported as Case 1192158.

    In my case, the problem is that some scenes have so many GameObjects. If the scene has many GameObjects (over 10k), it seems that calculating hash and getting cache (shown as Write Serialized File step) takes extremely long time (so second time build may be longer than first time build).

    I haven't received a reply from Unity yet, but I'll share it as soon as I get it.
     
  5. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Interesting. In our case, it happens when an asset bundle has "too many" assets. The more assets in that the longer it takes, in a very non-linear fashion, because what I pasted above causes Unity to load the assets into memory in CalculateSortIndex(). Since a lot of our assets are already on the target platform format (PVRTC textures for example), this causes Unity to decompress them into editor memory. Past a certain point it becomes impossible to build, as the editor process ends up taking up more than than the 64GB of memory allowed by having 32GB plus 32GB of swap. Very not ideal.
     
  6. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Out of sheer curiosity, when you have the time, could you run the editor through your favourite native code profiler (Visual Studio? Xcode?) when that happens and see where the time is spent on the native side?
     
  7. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Hi. I tried to profile editor while building asset bundles, but it crashed.

    It can be easily reproduced by following steps:
    1. Create new scene
    2. Add massive "Cube" object. (I added 180k cubes).
    3. Build assetbundle including above scene.

    You can see that secondary build time is much longer than first build time or player build time.
     
  8. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
  9. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Finally my assetbundle build time exceeds 6 hours. Temporarily I set UseCache to false and it is complete in about 1 hour. This issue is extremely annoying and significantly degrade my team's iteration efficiency.

    Note : ScriptableBuildPipeline 1.5.4 + Unity 2019.2.10f1.