STOP Making SLOW Games - Do THIS Instead!

STOP Making SLOW Games - Do THIS Instead!

swydev

2 месяца назад

12,373 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Weahl
@Weahl - 03.07.2024 22:52

Wow, that was really interesting, I thought the impact in performance would ve minimal.

Thanks for this video! ❤

Ответить
@CaughtByYourself
@CaughtByYourself - 04.07.2024 00:29

Hey swydev, I was on a business trip and couldn't verify the impact instantly, that's the reason I didn't reply yet. Was going tonreply and saw this video, hehe😅

No need to blur the name, but thanks that you did without showing clear name without asking!

I also wanted to mention that the line counters indicate if all values are statically known for godot or not. Green line indicator means better performance than grey. This indicator was introduced witj 4.x i think.

Ответить
@generrosity
@generrosity - 04.07.2024 06:29

WOW actual stats!

But, now my brain wonders about strings, and functions and function returns.... And if Godot does the Java trick I've heard about called inline functions? (As in the performance drop for splitting your functions toooo much) 😅 Yea it doesn't matter for most code. Cool preso!

Ответить
@americoperez810
@americoperez810 - 04.07.2024 07:02

Something you didn't mention in your video, but i think is equally just as important, is the developer experience when working with statically typed variables. Using statically typed variables allows Godots autocomple to work WAAAAY better, helping the developer write better, less buggy code.

For example, if you create your own class with its own functions and properties, the autocomplete will not show you those things sometimes unless you use static typing (in combination with type casting sometimes)

Ответить
@ozgurkalay7579
@ozgurkalay7579 - 04.07.2024 23:10

Better way for a lot of reasons is to specify the type. Eg:
var health: int
var velocity: Vector2

func get_health() -> int:
return health

func get_velocity() -> Vector2:
return velocity

Ответить
@Robnoxious77
@Robnoxious77 - 05.07.2024 03:28

if it’s that simple, it begs the question: why doesn’t the language always put the colon in by default, aka, under the hood, = just always equals := ?
There must be a reason it’s seperate, other than just something benign like “it only works with simple types”

Ответить
@NoSoyMako
@NoSoyMako - 05.07.2024 10:16

for me, I just love how static type is waaay more readable, look at this

func test(a, b):
return a + b

now using types:

func test(a:float, b:float)->float:
return a+b

Ответить
@TheSlimHim
@TheSlimHim - 05.07.2024 17:47

I also like to use it as it allows for better type hinting in the ide and if I forget the type of a var and do something silly, it throws an error.

Ответить
@MrXlee1967
@MrXlee1967 - 08.07.2024 11:33

Hi as a complete beginner to programming, how does one learn static typing from the get go? Is it the same as oop? Should I start with gdscript or python? Or something else. I don't have a galaxy brain 😁

Ответить
@mrjshzk
@mrjshzk - 08.07.2024 17:33

for me, the performance benefit is not really what I care but using static hints it's much easier to find/prevent runtime errors and you get autocomplete which are awesome things

Ответить
@comradecid
@comradecid - 08.07.2024 20:16

i'm fascinated by this, given that i've never seen anyone ever actually run stats for static typing's effect on compilation/performance. for the benefit of the audience, what i would love to have seen would have been a brief explanation of why there is a performance increase.

the increase arises from the fact that the compiler has to 'figure out' the type of every variable used in a codebase, and then allocate the corresponding type/memory, before then performing any calculations using those variables. and then those calculations need to be validated against its initial guesses, before it goes back and corrects them as needed. this is a lot of complex, time-consuming work that happens mainly during initial parsing/compilation, but also partially at runtime. by clearly indicating to the compiler what your intent is, and then reliably sticking with that intent, it removes this unnecessary work, and thus dramatically reduces processing time.

Ответить
@wukerplank
@wukerplank - 08.07.2024 22:28

Not to mention the warm fuzzy feeling of compile time safety 🥰

One question I have in my mind: With := Godot still has to do type inference (guessing the type, as you called it). Would declaring the type (var health: float = 50.0) be even more efficient?

Ответить
@TRUFANATIC
@TRUFANATIC - 09.07.2024 01:25

wow, thats cool, but sometimes you want to keep dynamic type, for instance - collider of raycast3d

Ответить
@mupmuptv
@mupmuptv - 09.07.2024 06:44

Once you get into static typing, you never go back

Ответить
@GlitchedCode
@GlitchedCode - 09.07.2024 13:03

To note here, you could have static typed your for loop as well

for i: int in range(LOOPS)

Not sure how much this would have affected the outcome, but something to point out

You can also tell your function what to expect to be returned with -> type before the colon when declaring a function. For example

func _process(delta: float) -> void:
void means to expect nothing to be returned but you can easily replace this with another data type for example
-> float
-> int
-> Vector2

and so on. Just two more things to share

Ответить
@carminator12
@carminator12 - 09.07.2024 13:35

Very interesting thanks.

Ответить
@TwoThreeFour
@TwoThreeFour - 09.07.2024 14:03

Static type in general programming is very recommended. It helps the compiler a lot when generating and optimizing the machine code (assembly) and resulting generally better execution as well.

Ответить
@ManjaDev
@ManjaDev - 09.07.2024 15:52

Godot Mono Still Faster btw

Ответить
@marclurr
@marclurr - 09.07.2024 16:44

There's almost no reason to ever use dynamically typed variables. There's never a good reason to change the type of a variable after it's defined.

Ответить
@_gamma.
@_gamma. - 09.07.2024 20:22

The walrus operator!

Ответить
@aqua-bery
@aqua-bery - 09.07.2024 21:17

That's it, statically types your dynamic programming language

Ответить
@panik2342
@panik2342 - 10.07.2024 00:08

Performance improvements are a nice plus, but the real advantage of types is documentation. Especially when working in a team, using a dynamically typed language is a recipe for disaster in the long run.

The type checker goes not away by using a dynamically typed language. The type checker is now you. So you will have cognitive overhead and have to reverse engineer the code base when you don't have types and come back to your project 6 months later.

The best example would be add_address(user) vs add_address(user: User): User.
With the second function, you will see on the first glance that the function will take a User and return a User. You can jump to the definition with your editor/IDE of choice, to see what a User actually is.
With the first function, you will have to read the code and usages to get a clue what's going on.

So besides cognitive overhead you have to have good documentation, which has to be revisited on refactoring and to be honest, documentation will diverge with the code, when time passes.

Ответить
@Bitlytic
@Bitlytic - 10.07.2024 07:39

There is also a setting in the editor that will automatically include these type hints in the default functions. Highly recommend everyone use it

Ответить
@HakanBacon
@HakanBacon - 10.07.2024 09:31

Dang, you got a new subscriber

Ответить
@UndeadFC
@UndeadFC - 10.07.2024 11:03

Can you make tutorial about shop system

Ответить
@TokisanGames
@TokisanGames - 11.07.2024 06:42

Static typing isn't used for performance, it's used to catch errors at compile time instead of runtime.

I mandate for my team, the only time := is used is if the type is named immediately after. Eg var v:= Vector3(0,0,0). Otherwise we always use the full format for code readability. Eg var v: float = 1.0.

You won't see a significant performance boost unless your code is bound by GDScript, which it should not be if you're programming optimally. Your GDScript should be mostly event driven, pushing the work onto the engine. If your game is GDScript bound, static typing is only a bandaid for poor design. Greater improvements will come from restructuring your code.

Ответить
@AnkobiaStudios-bs4vg
@AnkobiaStudios-bs4vg - 13.07.2024 10:35

Im finally sold. My small game just happens to run 1m computations (3D procedural dungeon). And yeah it's slow. But now it can be 20% faster than slow!

Ответить
@MrFoof82
@MrFoof82 - 14.07.2024 03:38

Another consideration is if your end user is on mobile on anything with a battery such as a laptop. The less work the computer is doing, the better the battery life.

Ответить
@adiveler
@adiveler - 14.07.2024 12:49

For someone who originally learned programming from languages such as C# and Java - Static typing just feels more right for me!

Ответить
@arutonee5434
@arutonee5434 - 14.07.2024 17:28

In my opinion, the performance of static vs. dynamic typing does not matter, even in the high-performance context of a game. 99.9% of the time, the performance bottleneck comes from an inefficient implementation, never the language itself being slow. The biggest benefit of static typing in my eyes is the ability to implicitly assert the type of a variable and ensure that it will not change. It makes bugs in the form of accidental redefinition and misspelled variables more likely to be caught earlier in the call stack, it helps make common programming idioms easier to notice, as you do not ever have to worry about the type of a given variable changing, and you won't ever have to do explicit type assertion in your functions.

Ответить
@Vodboi
@Vodboi - 16.07.2024 00:43

I feel like this video is missing the entire point of statically typed languages. It's mainly about type safety, and makes it a lot easier to keep track of what functions and operations you should be allowed to perform with your variables. I find this especially useful when variables can be transferred across different scripts, like in functions and signals. Also makes writing code easier with autocomplete suggestions.

Ответить
@GamedevDen
@GamedevDen - 16.07.2024 18:54

Faster or not, static typing is the way to go. This helps you prevent bugs and unknown errors later down the line. Take your example of an int becoming a float later in the code; sure, it could be handy in a certain situation, but in that case, change the underlying type. Imagine you're creating a grid system, and use ints for the position. It would be strange if you suddenly got a bug where the grid position is 6.423 no? That is the strength of static typing, as it makes that impossible.

(Not hating on the video, just a little comment :D)

Ответить
@teaemperor1055
@teaemperor1055 - 17.07.2024 01:33

As a c# web developer static typing is my jam, to default to non static is crazy 😮 and lt can lead to less readable code. Always use Typescript for the frontend

Ответить
@stintav
@stintav - 17.07.2024 03:07

I just can't look at "var dookie=1",
I love typing "var dookie: int = 1

Ответить
@mudscuffer
@mudscuffer - 17.07.2024 22:51

Accurate benchmarking and profiling is more complex than the very simplistic code you showed. For example, for most scripting languages you'll want to exclude outliers caused by garbage collection. Not to mention that micro-benchmarks like yours that show 20% improvement may well have negligible impact on more realistic code. That said, static typing all the way for me, I would not go back to dynamic typing for anything more than 10 lines of code.

Ответить
@Mohandas.Gandhi
@Mohandas.Gandhi - 18.07.2024 00:52

Sick 2j though

Ответить
@RexSacriticulus
@RexSacriticulus - 18.07.2024 20:00

There's no actual static typing in GDScript, just type locking. Any piece of data is technically a Variant.

Ответить
@skellien
@skellien - 19.07.2024 07:42

Hey guys, if you keep forgetting to static type your variables (or just want godot to yell at you), there's a project setting in the Debug > GDScript > Untyped Declaration option to change into Error. Hope this helps~

p.s:
funcs also need to be type declared like, func example() -> void:

Ответить
@ReeceTheTroll
@ReeceTheTroll - 21.07.2024 00:49

Disliked cause of AI thumbnail lol.

Ответить
@Zlorak
@Zlorak - 24.07.2024 05:21

Static typing is not really for the speed, but to help write organized code and to pinpoint bugs faster. Like someone said, once you use it and understand why, you never go back.

Ответить
@Amonimus
@Amonimus - 24.07.2024 13:18

Bonus: it's just more convenient for self-documentation, and Godot can autocomplete functions for you if you tell explicitly which class/type is put into a variable.

Ответить
@JuhoSprite
@JuhoSprite - 01.08.2024 23:57

I use c=3 it works much better

Ответить
@Dr.Bamboo-dev
@Dr.Bamboo-dev - 07.08.2024 09:54

I wasn't actually aware of the performance benefit. I use static typing so that I can avoid bugs and easily identify mistakes when I forget what data type I need.

Ответить
@baptistevillain148
@baptistevillain148 - 08.08.2024 11:09

As a java engineer during the day, my brain could not code without it. Now I discover that it even makes the game faster, great!

Ответить
@Uhfgood
@Uhfgood - 14.08.2024 19:46

Well imagine my confusion coming from a Pascal background where := means something entirely different :-) -- Honestly I don't know why dynamic typing is a thing anyways. As you showed not only is it slower, but you might be more prone to errors if you're just making types anyways. I understand, for instance, if you're using an integer for a state machine, you might want to make it more explicit by later changing it to a string, however changing a variable definition to use a different type is not really that hard, and even in here it's almost too easy. The only thing is I might would recommend against the := because you may forget, and in some cases not even remember that you made it a static type. Might be a better deal to just do it long hand var myVar : string = "hello"

Ответить
@ArturoAlbero
@ArturoAlbero - 09.09.2024 20:17

Not only the performance is better, but also the autocompletion and the legibility of the code. Actually, I don't think you should use dynamic type at all, it is much more prone to error and it allows clumsier programming (which is a problem in the long run). And, as you said, it's just a ":" for the simpler and more used types.

In Godot, however, the first approach was dynamic typing because GDS is based on python (a dynamic typing language). The static typing was implemented for Godot 4 (I think), that's why some documentation does not use static typing.

Ответить