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

Addressables: 14 seconds to load 100 text files, total size less than 0.5 megabytes, on a 9900K.

Discussion in 'Addressables' started by aaversa, Feb 28, 2022.

  1. aaversa

    aaversa

    Joined:
    Sep 5, 2016
    Posts:
    41
    As the title says. This performance is ludicrously awful. What is going on here? I'm experimenting with Addressables to help with Switch load times; on my first title I used AssetBundles, which were pretty snappy. We got load times to less than 30 seconds for the entirety of all game data, which was several hundred megabytes.

    With addressables, using LoadResourceLocationsAsync and then LoadAssetAsync, it is taking 14 seconds - yes, 14 - to load an addressable group with 100 TextAssets.

    Things I have tried:

    * Switching from LZ4 to Uncompressed
    * Disabling CRC checks
    * Setting backgroundLoadingPriority to HIGH
    * Enabling Contiguous Bundles
    * Enabling "Use UnityWebRequest for Local"
    * Bundle Mode: Pack Separately OR Pack Together

    Literally none of these things make any difference, or at best they *slow* the load time by 0.1 to 0.5 seconds.

    LoadResourceLocationsAsync is extremely fast; the problematic and slow section is as follows:

    Code (CSharp):
    1.         foreach (IResourceLocation location in handle.Result)
    2.         {
    3.             AsyncOperationHandle<TextAsset> textHandle = Addressables.LoadAssetAsync<TextAsset>(location);
    4.             yield return textHandle;
    5.  
    6.             if (textHandle.Status == AsyncOperationStatus.Succeeded)
    7.             {
    8.                 textAssets.Add(textHandle.Result);
    9.                 listOfMostRecentlyLoadedFileNames.Add(textHandle.DebugName);
    10.             }
    11.             if (textHandle.Status == AsyncOperationStatus.Failed)
    12.             {
    13.                 TDebug.LogError(textHandle.DebugName + " did not load");
    14.             }
    15.             Addressables.Release(textHandle);
    16.         }
    I'm at a loss. This is many orders of magnitude slower than any other resource loading we've used. What are we doing wrong?
     
  2. cado82

    cado82

    Joined:
    Jul 29, 2020
    Posts:
    25
    Some questions:
    1. Is this in a player build or in the editor?
    2. Is the group remote or local?
    3. If remote, where are the assets hosted?
    4. The code you pasted seems to load each file and then release it before moving to the next one. Was that intentional?
     
  3. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    This is likely a issue with the way yielding is done, rather than the loading itself.
    when you yield the textHandle, a minimum of one frame will occur before it continues.

    instead you should start all the operations, then wait until all are done.

    Something like this rough code.
    Code (CSharp):
    1. List<AsyncOperationHandle<TextAsset>> handles = new xx;
    2. foreach (IResourceLocation location in handle.Result)
    3. {
    4.     AsyncOperationHandle<TextAsset> textHandle = Addressables.LoadAssetAsync<TextAsset>(location);
    5.     handles.Add(textHandle);
    6. }
    7. bool complete = false;
    8. while (!complete)
    9. {
    10.    complete = true;
    11.    foreach(var h in handles)
    12.          if (h.isDone == false ){ complete = false; break }
    13.     if (!complete)
    14.         yield return null;
    15. }
    16. }
    or better yet, start the handles, then do textHandle.Complete to register when it is complete, which can happen earlier.