Godot Static Typing - Is It REALLY Faster?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you ever been doing a gdau tutorial and seen this what is it why do people use it and when should you use it I recently had a subscriber ask me to use this type of symbol in my tutorials instead of a classic equal sign I'd used it before but since most of my games are rather small in scale I'll admit I didn't see much difference this got me thinking why do people use it I mean even the gdau documentation uses a regular equal sign in a lot of places so why would we ever need anything different so I decided to run some tests and see for myself in gdau this symbol is a way to statically type your variables and seemingly works just like a regular equal sign there's actually much more going on under the hood let me explain when defining a variable in gdau you can choose to use one of four main formats constants are set to their initial value and never changed trying to change the value later will give you an error you can also Define a variable using a regular equal sign this will allow you to change it later to a different data type so if you originally used an integer you can easily change this to a float later on the last two ways are functionally very similar and are known as static typing if you know what the data type for your variable is you can explicitly tell gdau to use that type alternatively you can use this as a short hand for the same thing and gdau will guess the type based on the default setting you used these two notations are essentially identical in how they are treated and both end up with statically typed variable whose data type cannot be changed later but why use static types at all admittedly for smaller games there's little to no difference from an in user perspective but I wanted to test this out for myself and find out if there was any performance improvements for using static type variables so I wrote a script that had two Loops one for variables with static type and one for variables without one each Loop would run 100 million times to give us enough computational scale to be relevant here's what I found for my first round of tests I wanted to see if there was a difference when you changed the value of a variable but kept the same data type I found that simply changing 1 to 2 2 to 3 and so on that there was in fact a small Improvement for vectors statically typed variables show an 88.6% improvement in performance integers showed a 7.9% Improvement and floats demonstrated around 8.2% increase in performance it's pretty good right well for my second test I wanted to try some calculations with the different types just a simple calculation on each generation of my Loop blew me away adding two statically typed vectors together showed a huge Improvement in performance coming in at 20.11% faster integers and Float showed similar results coming in at 20.8 7% and 20.94% respectively adding a mix of variables brought the performance boost up to just over 21% and multiplying a mix of variables demonstrated a whopping 21 1.56% increase in performance so what does this all mean if you're building a small game and not doing 100 million computations at the same time you can basically use whatever you'd like but if you're working on a larger project simply adding a colon in front of your equal sign when defining a variable can make your game run around 20% faster which is pretty significant I hope this video helped shed some light on why you'd want to use static types in gdau and thanks so much to the subscriber who pointed this out to me it turns out there can be a huge performance boost to your game by remembering this one simple thing
Info
Channel: swydev
Views: 6,101
Rating: undefined out of 5
Keywords: gamedev, game dev, godot, godot 4, godot tutorial, make video games, game dev tutorial
Id: i6FPrpW0TOM
Channel Id: undefined
Length: 3min 34sec (214 seconds)
Published: Wed Jul 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.