Unity3D Tutorial: Comparison of AssetBundle Loading Efficiency

foreword

If you want to compare the loading efficiency of AssetBundle, you first need to know the main two ways to load AssetBundle, namely new WWW(url) and WWW.LoadFromCacheOrDownload. The specific usage of the two methods can be found in the official API, and there are not many in this article. introduced.

1. new WWW simply loads AssetBundle into memory

2. WWW.LoadFromCacheOrDownload is to write the AssetBundle into the cache, and then read the AssetBundle from the cache when the AssetBundle needs to be loaded to achieve an acceleration effect, and only save some necessary cache pointer information in the memory, so it is very economical Memory is what most people choose to use.

Comparison of the loading efficiency of the two methods:


image


image

Test Results:

1. On the PC, the efficiency of the two methods is only about 40% different for the first time. Maybe the hard disk on the PC side has a relatively fast cache and read and write speed, while on the mobile side, the difference in efficiency is as much as 2 times.

2. The second method is very fast when reading twice

3. The second method is recommended

Summarize:

According to the above comparison, it can be seen that WWW.LoadFromCacheOrDownload is slightly slower than new WWW when it is loaded for the first time, but after the second loading (such as exiting the game program and entering the game again, it is also considered a second loading), WWW. LoadFromCacheOrDownload will bring faster loading speed and save more memory. Even if the resources of more than 100 megabytes are fully loaded, they will only occupy about 10MB of memory, because Unity has made a hard disk cache for them, which has opened up a lot of memory. Disk space in exchange for consuming a lot of memory. And after the AssetBundle is loaded, the instantiation speed is no different from that of new WWW. WWW.LoadFromCacheOrDownload wins!

Other notes:

When using WWW.LoadFromCacheOrDownload to load, if the disk space is full and all cache files are in use, WWW.LoadFromCacheOrDownload will call the new WWW() method to load the resource into the memory. The situation of insufficient disk is better solved.

In the cache, the only way for Unity to identify resources is the resource name + version number, so no matter what kind of resource, the resource name cannot be the same.

All operations on the cache are in the Caching class, which only provides simple query and clear operations.

Guess you like

Origin blog.csdn.net/bycw666/article/details/123733100
Recommended