Cache or not to cache? (links)

Hello. I’m going through Glitch Garden 144 (Set and Place defender).
Thank you for the course, it’s so great and fun to learn with it!

I’ve been wondering for some time - we do not cache links as we did in previous tasks.
Is it worth doing to improve performance or is it not?

My main concern - we speedup search of elements when we cache those links, but at the same time we had to spend memory on links(not much though, but could it be an issue for mobile for example?).

Could you please clarify when we should cache and when it’s not a good idea?

Thank you -)

Hi Evgenii,

Welcome to our community! :slight_smile:

I’m not exactly sure to what code you are referring but I agree with what you wrote. The references to objects which we access multiple times in another instance should be cached for reasons of performance, especially when we get the reference via GetComponent or, even worse, FindObjectOfType.

If Rick didn’t cache the reference, the reason for that is either that we access the object only once, or he forgot to do that. Feel free to optimise your code.

Did this help?

Hello Nina,

Yep, it helped me, thank you for fast response -)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms