Cache for FindAssetEntry making our building very slow

Recently, I upgraded Addressables from 1.19.19 to 1.20.3, and found building aab/ipa became slow. Before, building aab took about 20 minutes. After upgrading, it took 4.5 hours!

After some investigation, I found it’s due to building cache for FindAssetEntry repeatedly, which was added in Addressables 1.20.0.

Each time we build the aab(or ipa), we remove all entries from a group which contains shared assets between bundles, and execute our custom CheckBundleDupeDependencies rule to put all current shared assets into this group. During this phase, RemoveAssetEntry is called multiple times, and the cache for FindAssetEntry is rebuilt repeatedly.

Besides that, we have some tools that modify Addressable settings, which can also be affected by this issue, for exmaple:

  • We use this tool(GitHub - favoyang/unity-addressable-importer: A rule based addressable asset importer) to set asset addressable automatically. When we update other people’s changes, there may be a large number of assets need to be processed.
  • We have some special versions which only have a part of assets in the aab/ipa. Other assets will be downloaded by Addressables.DownloadDependenciesAsync at the runtime. So, before building these versions, we execute a tool to set labels for these assets.

For our project, this cache is not so helpful, since there is only about 30 Addressable groups in the project (Although, the group containing shared assets is very large). Currently, I just disable the cache for FindAssetEntry to avoid this issue.

Hope it can be imporved in the future version.

I found another issue which is similar to the issue above.

Each time I change a field of a MonoBehaviour which is attached to a Addressable prefab in the inspector, the editor takes some time to save it.

After futher investigation, I found it’s due to AddressableAssetSettings.OnPostprocessAllAssets considers the prefab is an Addressable asset, so it calls AddressableAssetSettings.SetDirty to clear m_CachedHash. When the prefab is modified next time, it had to rebuild the cache in AddressableAssetInspectorGUI.GatherTargetInfos.

I added some code to log the execution time of AddressableAssetInspectorGUI.GatherTargetInfos, and found it took about 1.1 second on my PC(with i7-12700 cpu and SSD) each time I modified the prefab.

UPDATE:
After I commented the code for the cache in AddressableAssetInspectorGUI.GatherTargetInfos, the execution time of AddressableAssetInspectorGUI.GatherTargetInfos reduced to about 0.1ms