#Question about singleton performance

1 messages · Page 1 of 1 (latest)

gritty shadow
#

Say I have a singleton, which is basically a "public static instance" variable on the singleton. Is it good for performance if I keep calling MyScript.instance many times, or should it always be cached into a variable? So if a script needs to access the singleton of a different script many times, should I do this:

private SingletonScript singleton;
void Start()
{
singleton = SingletonScript.instance;
}

Is this necessary or is it ok to keep calling SingletonScript.instance multiple times? And what is the performance difference?

ivory vector
#

very minor difference

#

premature optimization