Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Load resource without CPU spike

Discussion in 'Editor & General Support' started by hvilela, Oct 22, 2012.

  1. hvilela

    hvilela

    Joined:
    Dec 6, 2010
    Posts:
    24
    I'm trying to load a relative large image but no matter what I try there's always a noticeable CPU spike when it's running at the iPad.
    Here's my code with the better result so far:

    Code (csharp):
    1. WWW www = new WWW(path);
    2. yield return www;
    3. AssetBundle bundle = www.assetBundle;
    4. AssetBundleRequest request = bundle.LoadAsync("MyResourceID", typeof(Texture2D));
    5. yield return request;
    6. material.mainTexture = request.asset as Texture2D;
    Everything is async, but still noticeable. The main CPU spike is Texture.IntegrateloadedImmediately, but I have no idea what it does and how I can avoid it or at least reduce it.

    Any suggestions?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can alter the thread priority of the request.
    But it won't change the last part of the hit which comes from 'creating a gpu texture' and it will likely always create a 'halt' even if just a tiny one. The smaller the texture memory wise (so small size or pvrtc compression) the shorter that halt, at best even inexistant.
     
  3. hvilela

    hvilela

    Joined:
    Dec 6, 2010
    Posts:
    24
    My bundle has only 300k, it contains just one 1024x768 compressed image and still the "Texture.IntegrateloadedImmediately" costs me 0.3s in the iPad. Don't you think it's sounds too much?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    1024x768 can not be compressed as thats not power of 2 square, which is a requirement for PowerVR Texture Compression.
    Anything thats not pvrtc hardware compressed is uncompressed, either 16 or 32bit.
    In that case the time would be reasonable likely. Also if its an ipad1, then its important to realize that that is weak hardware (apple has phased out any support for it for good reasons)

    And if its a lot depends on what else is going on.
    But as mentioned, change the Thread priority so it has a lower load. Just be aware that the loading then will take significantly longer.

    I personally dropped any asset bundle usage on mobile for the time being as their is something fishy.
    It performs abysmal when compared to Resources.Load, not only bloating memory like stupid and being bugged on LoadFromCacheOrDownload which is meant to decompress it into the cache which it does not do, it also takes eternities to load stuff out of the bundles even if you change the thread priority to high, set it to low it and it takes an order of a magnitude and more of the time to load from asset bundle (even with just the texture in) compared to how long it takes from Resources
     
unityunity