Search Unity

Feedback Addressable asset bundle WriteSerializedFiles performance

Discussion in 'Addressables' started by AlkisFortuneFish, Aug 1, 2019.

  1. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Just a quick one, while looking through the logs, I spotted that every write in SBP WriteSerializedFiles seems to trigger UnloadUnusedAssets.

    Now, I get why this is done to preserve memory but can't it be batched to happen every few operations?

    Each UnloadUnusedAssets costs between 160 and 200ms on my machine. We have 3000 asset bundles or so at the moment. For 3000 asset bundles that is nearly 10 minutes spent just performing asset GC.

    I did try and trace it to see if it happens in managed code but it does seem to happen in native code wrapped in the ContentBuildInterface. Maybe an option to add there in future?
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    We'll look into it, but if it happens in native code, it's a lot harder for us to get a fix in (and really hard to backport to older versions of Unity).

    Do your bundles have scenes in them? I believe we load all scenes as we build them. When a scene is loaded (in single mode) it calls UnloadUnusedAssets. Not sure if that's what's going on here, but it could be. We don't particularly like that it does that, but if that's what's triggering this unload, we most likely won't be able to fix it. That's one of those long standing "features" in Unity that's hard to over turn.
     
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    I sort of suspected that to be the case, although at the moment use getting up to date with addressables (long and painful story...) has been the main roadblock to updating to newer versions of Unity, so now I'm finally tackling this any improvements in future versions of the engine itself would be welcome.

    Nope, they are all raw assets, mainly scriptable objects depending on textures, models etc. To be a tad more precise, they are assets for a *very* bespoke UMA/Addressables integration.

    Even though they do not contain scenes, I am getting some spam about a missing script on our main scene when it's building, which would indicate repeatedly opening that scene for whatever reason. I do wonder why that is. Could it be re-opening what scene was loaded at the time the build was triggered?

    Edit: Opening an empty scene before triggering the build reduces the time spent on UnloadUnusedAssets to ~35ms per file. Am I am missing something? I would have expected Unity to have very little from the environment used when the build was triggered loaded while it's building bundles.
     
    Last edited: Aug 1, 2019
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    We looked into it, and it does seem to be unrelated to scenes, and is an engine issue. We're looking at a fix, but again, may be hard to backport once we can get it in.

    The 35ms thing is puzzling.