#Godot #GDScript tip: type hints can not only improve code readability and prevent errors, but also drastically improves runtime speed basically for free as the interpreter is able to use type information to optimize function calls and variable assignments. In this example, even a few extremely simple functions (only a couple lines long each) were made ~20% faster by just adding type hints.
Docs: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/static_typing.html
Example: https://gdscript.live/?script=Y2xhc3MgU29tZXRoaW5nOgoJdmFyIGEKCmZ1bmMgbWFrZV9zb21ldGhpbmcoKToKCXZhciB0aGluZyA9IFNvbWV0aGluZy5uZXcoKQoJdGhpbmcuYSA9IDQKCXJldHVybiB0aGluZwoKZnVuYyB1c2Vfc29tZXRoaW5nKHRoaW5nKToKCXJldHVybiB0aGluZyArIDUKCmZ1bmMgbm9fdHlwZV9oaW50cygpOgoJdmFyIHggPSBtYWtlX3NvbWV0aGluZygpCgl1c2Vfc29tZXRoaW5nKHguYSkKCmZ1bmMgbWFrZV9zb21ldGhpbmdfd2l0aF9oaW50KCkgLT4gU29tZXRoaW5nOgoJdmFyIHRoaW5nIDo9IFNvbWV0aGluZy5uZXcoKQoJdGhpbmcuYSA9IDQKCXJldHVybiB0aGluZwoKZnVuYyB1c2Vfc29tZXRoaW5nX3dpdGhfaGludCh0aGluZzogaW50KSAtPiBpbnQ6CglyZXR1cm4gdGhpbmcgKyA1CgkKZnVuYyB3aXRoX3R5cGVfaGludHMoKSAtPiB2b2lkOgoJdmFyIHggOj0gbWFrZV9zb21ldGhpbmdfd2l0aF9oaW50KCkKCXVzZV9zb21ldGhpbmdfd2l0aF9oaW50KHguYSkKCmZ1bmMgbWFpbigpIC0+IGludDoKCUdEU2NyaXB0TGl2ZS5wcm9maWxlKG5vX3R5cGVfaGludHMpCglHRFNjcmlwdExpdmUucHJvZmlsZSh3aXRoX3R5cGVfaGludHMpCglyZXR1cm4gMQo=&indent_type=0&indent_size=4
#Godot4 #gamedev #programming