The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+2 votes

I am quering a variable stored in an autoload singleton, with if elif I must call global.var every time I use the variable. but if I use the match I only call the variable once ... will that make the query slightly faster?

in Engine by (90 points)

Is retrieving global variables that slow?

apparently there is no effect on speed

1 Answer

+5 votes
Best answer

match and if get compiled as the same sets of instructions, none is particularly faster than the other. match is essentially a different way to express things in a more concise way. It certainly makes you write the variable only once, but it still has to compare its value for each case (i.e it's not a jump table like in C).

by (29,360 points)
selected by

oh ok, thanks ! very useful

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.