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. Dismiss Notice

Wildly fluctuating bundle sizes - what's causing it?

Discussion in 'Addressables' started by Xarbrough, Jun 26, 2021.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    I have it set up via
    BuildPlayerWindow.RegisterBuildPlayerHandler
    so that Addressables are built when the regular build button is pressed in the Unity build settings window. Overall this seems to work nicely, but recently I noticed a strange issue:

    Sometimes, when I build, the produced bundles are 300 MB large. If I then do "Clean All" all in the groups window and rebuild again, they are only 150 MB. I still build via the regular player build button, but with my custom code calling:

    Code (CSharp):
    1. //AddressableAssetSettings.CleanPlayerContent();
    2. //BuildCache.PurgeCache(true);
    3. AddressableAssetSettings.BuildPlayerContent();
    4. BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options);
    I then go back to build setting window, untick the development box and rebuild. Now, the bundles are 300 MB again. As far as I know, the development/debug option has nothing to do with Addressables. Also, how could the release version be twice the size. When I clean manually and rebuild it seems to be fixed again.

    Here are my results from the last compression test:

    upload_2021-6-28_21-16-46.png

    Of course the size will change if I change the compression override setting, but the point is, look at how it starts at the bottom with 300 MB, then I change no settings, only do a Clean All, rebuild and suddenly 147 MB. When switching to ETC it jumped back to 300, but after a clean went down to 147 again. Again when switching to ETC2 and so on.

    For some reason, the fix cannot be reliably applied via code. My commented out code shows what I've tried, but this only works sometimes, so maybe it's got nothing to do with the cleaning per se, but only with building twice in a row.

    Any idea where this could be coming from? I would report a bug, but of course the issue only happens in my multi-gigabyte project and I don't know the exact steps.
     

    Attached Files:

    Last edited: Jun 28, 2021
    Peter77 likes this.
  2. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    I guess there must be 2 bundles of the same asset on your local path. The old one and the new one, and both of which are getting copied to the Streaming Assets. Check the default local path location which should be Library\com.unity.addressables\aa\Android\Android unless you have changed it.
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    I've checked and inspected the contents of the APKs. Turns out, for whatever reason, the bundles are just much larger sometimes, but the number of bundles is the same.

    Capture.PNG

    upload_2021-6-26_17-15-32.png
     
  4. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Did you check your local build path? Default path - Library\com.unity.addressables\aa\Android\Android

    Was there a single bundle for eg "shared_rooms_assets_all" when you built it for the 2nd time?
     
  5. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    Yea, I looked at the library location and it mirrors exactly what went into the APK, both times. I also run "Clean Content" before each Addressables build, which deletes the files at the local build path before building new bundles.

    I wish I could check the contents of the bundles to find out what es causing the large difference, but it feels like the large version could be without compression. I have LZ4 compression set on all groups, but I'll test how large the bundles become without compression. If that turns out to be the 320 MB instead of 170, it might be losing the compression settings in some cases.
     
  6. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Looking at your bundle names again, I guess it might be some other issue. I add hash to my filename because of which it creates a new filename every time I make a build because of which my load path contains both the old and the new files.
     
  7. LilMako17

    LilMako17

    Joined:
    Apr 10, 2019
    Posts:
    43
    Xarbrough likes this.
  8. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    It's all difficult. The asset-bundle-analyzer tools seems nice, but it throws exceptions when I run it on my bundles. It only parses the first two bundles and then fails due to some encoding issue. It hasn't been updated in a few years, so probably not compatible with Unity 2021. Hm...
     
  9. LilMako17

    LilMako17

    Joined:
    Apr 10, 2019
    Posts:
    43
    the script fails for me on 2 bundles, the unity generated shaders bundles, and my one custom bundle that contains only ScriptableObjects. I always have to delete or move those 2 bundles to get the script to work, but after that it's fine.
     
  10. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    Thanks, those are good tips, but I'm not making much progress. I already deleted most of the bundles and also tried different versions of the tool, but I can't manage to inspect those bundles that actually have different sizes. So far I could only compare two bundles which are identical. Maybe that's part of the crux: the too large bundles are somehow broken and the analyze tool can't even parse them.
     
  11. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
    I'll flag with the team for some guidance. Which version of Addressables are you using?
     
  12. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    Thanks! 1.18.9 in Unity 2021.1.12
     
  13. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi you can use WebExtract and binary2text to convert the bundle files to a readable txt file. The instructions can be found here: https://support.unity.com/hc/en-us/articles/217123266-How-do-I-determine-what-is-in-my-Scene-bundle-

    There is also this AssetBundle Browser tool that is more user-friendly but struggles when reading large bundles. https://github.com/Unity-Technologies/AssetBundles-Browser

    The issue sounds like a bug of sorts.. definitely send it our way once you have a working repo. It could be related to this known issue where a CRC mismatch occurs (in other words the bundle has changed) when rebuilding Addressables after restarting the editor & doing a "Clean All".
     
    Xarbrough likes this.
  14. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
    Do you have a public issue tracker link to it? I would like to keep an eye on it.
     
  15. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Peter77 likes this.
  16. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346