Should I mark the type of defined variables/constants?

Godot Version

4.3-stable-mono

Question

I’ve heard that if you mark the type of the returned variable in a function, then Godot already knows how much memory needs to be allocated for it and the program runs a little faster. Do I need to mark the type of variable for defined variables that have a value? Will it give even a minimal performance boost?


It should give a minimal performance boost and better autocomplete, but for Dictionaries not so much… the keys and values are Variants, I think 4.4 add typed dictionaries so you could use Dictionary[String, int] with the next stable version.

2 Likes

From the docs.

Although the type of constants is inferred from the assigned value, it’s also possible to add explicit type specification:

No mention of speed improvement since constants are compile time calculations.

1 Like