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

Unity should internally cache .transform for a valid speed boost.

Discussion in 'Wish List' started by hippocoder, Jul 16, 2011.

  1. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi,

    I couldn't think of any reason why unity via mono would not cache .transform for that object after the first call to it. This would speed up nearly all ios games.

    So how about it guys? do a bit of caching in realtime to boost performance of various things. I know we can cache it ourselves but that it a fair bit of micromanagement and not that well-known.
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Nearly all ios games? How about all games.

    This really should happen, but if there is some unforeseen reason as to why it isn't automatically cached, they should at least make it more well known that it is calling GetComponent. I can't remember how many times I have pointed it out and it was received as a Unity Jewel of Wisdom.
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Are there any other things that you can think of that would benefit from a cache scheme built into unity?
     
  4. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    It's not cached?
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Its cached but you access it through a property with all its implications.
     
  6. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    So, do you mean that doing:

    Transform myTransform = transform;

    At my Start(), and then using myTransform instead of the built in transform in my Update(), would boost performance?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Correct.

    --Eric
     
  8. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Hmm... thanks, good to know.
     
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Not sure it was cached back then when I requested it, but it is cached now (within the engine, and incurs a tiny lookup cost), which is really quite OK for the most part. But much more isn't cached, and I was thinking it would be less to code if we could specify to unity what isn't or is cached in this manner going forward. Small issues with the awareness developers now have about caching.
     
  10. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Wait, so which one is it? Should I cache, or is it already cached internally?
    I am talking solely about transform, not other components.

    If cached internally - do you know from which version? Is it 4 or pre 3.x?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Yes. ;) go.transform is faster than go.GetComponent(Transform), but not as fast as caching the transform yourself.

    --Eric