Awsome as always. Have you considered making a series in which you make a simple game architecture and explain how different patterns coexist together?
I'd love to have a series of videos showing how to create robust modules to power any game you wish to make? Audio Manager, Save System, Health/Weapon/Inventory Manager, etc.
Dude, how are you writing code at this GOD level 🔥🔥... It looks so clean and neat to read even without comments. You literally playing around with it just like that. Thanks for explaining the closure thing in detail. I can't find a better tutorial than this.
@@git-amend I constantly upgrade my passion project based on your tips :D Have a backlog of improvements now ;) It has to run on Quest 3 Android and PC VR. All good so far but will get better. Thanks!
In other words, you mean to manage the captured variables in the form of structures, right? So what are the benefits of using the Lambda? I actually have a little bit of a question.
teacher's code is to build a structure to replace the "closures," right? I understood it as the concept of avoiding the GC. Then, can I pool this, ltoo like object pool?
Yes, you’re correct-the approach involves managing captured variables explicitly in a structure to replace standard closures, thereby avoiding GC allocations caused by implicit heap allocations. Lambdas are still useful because they offer concise, readable syntax and integrate seamlessly with C#'s delegate and LINQ features. However, in performance-critical code, like Unity’s `Update` loop or frequent callbacks, avoiding heap allocations is essential, which is why we replace lambdas with explicit structures. And yes, you can pool these structures, much like object pooling, to reuse them efficiently and further reduce GC pressure, but maybe add a 'Reset' method to the struct so you can set new values.
This is nice, but I'm not sure about adding all of this complexity because of closure. Did you benchmark this on some heavy delegate usage? I do wonder if this is something noticeable. I am working on a pretty big project and the current bottlenecks are order of magnitude larger than this. Just wondering if, for example, starting a new project with such a struct would be actually worth it. I do worry more about anonymous delegates and memory leaks. And great content as usual! Though I think having a benchmark for this specific case could prove helpful, as I am sure newer programmers would take a few things as gospel, but it's important to understand the pros and cons.
Profile is the answer each project is different and sometimes the compiler does a lot of optimizations. Because of how my projects are architecture, I use a lot of delegates and they aren't my bottlenecks.
@@marlonruvalcaba386 Of course, each project is different, and you need to profile to understand your needs. I doubt any project will ever have this as the actual bottleneck, I am just wondering how much you could actually get from doing this vs the complexity it will add.
The CognitiveComplexity can be useful, it will tell you if your code is getting overly complex. I also use the Classic UI plugin because I prefer the old look of the IDE. Key Promoter X plugin will help you learn the keyboard shortcuts, but you will want to disable it after a while. If you are coming from VS Code, I would also go to Settings > Keymap and choose "VS Code" there.
In my experience it's not really going to affect performance unless we're talking allocations in the thousands. It's like the whole debate on whether or not it's ok to use LINQ, those monads cost.
Happy Holidays! Hope everyone is having a break of some kind! Link in description to Blog post about Heap Allocations Viewer! 👍
Thanks a lot man, literally the only channel who posts videos about advanced stuff that i didn't even know they exist. Keep it up bro!
Awsome as always. Have you considered making a series in which you make a simple game architecture and explain how different patterns coexist together?
Yes, I have. It's a good idea and probably something we can do in the coming year!
I'd love to have a series of videos showing how to create robust modules to power any game you wish to make? Audio Manager, Save System, Health/Weapon/Inventory Manager, etc.
Adam, Thank You for all the great videos and sharing your knowledge. Please keep it up! It's awesome!
Thanks, will do!
Another tool for my arsenal. THANKS!!!
You're welcome!
Dude, how are you writing code at this GOD level 🔥🔥... It looks so clean and neat to read even without comments. You literally playing around with it just like that. Thanks for explaining the closure thing in detail. I can't find a better tutorial than this.
Thank you so much for the kind words! I’m really glad you found the explanation clear and helpful!
I will say it as simple as I can -> "Best YT content GOTY+ Award" :D thank you!
Wow, thanks!
@@git-amend I constantly upgrade my passion project based on your tips :D Have a backlog of improvements now ;) It has to run on Quest 3 Android and PC VR. All good so far but will get better. Thanks!
Thanks as always!!
My pleasure!
In other words, you mean to manage the captured variables in the form of structures, right?
So what are the benefits of using the Lambda? I actually have a little bit of a question.
teacher's code is to build a structure to replace the "closures," right? I understood it as the concept of avoiding the GC.
Then, can I pool this, ltoo like object pool?
Yes, you’re correct-the approach involves managing captured variables explicitly in a structure to replace standard closures, thereby avoiding GC allocations caused by implicit heap allocations. Lambdas are still useful because they offer concise, readable syntax and integrate seamlessly with C#'s delegate and LINQ features. However, in performance-critical code, like Unity’s `Update` loop or frequent callbacks, avoiding heap allocations is essential, which is why we replace lambdas with explicit structures. And yes, you can pool these structures, much like object pooling, to reuse them efficiently and further reduce GC pressure, but maybe add a 'Reset' method to the struct so you can set new values.
@@git-amend Thank you so much. You always give me new horizons. I'm studying using your code, and I really respect you.
You and Smack are my teachers.
@@git-amend You have a GOOOD talent who can easily explain it to a bad-headed person like me.
This is nice, but I'm not sure about adding all of this complexity because of closure.
Did you benchmark this on some heavy delegate usage? I do wonder if this is something noticeable.
I am working on a pretty big project and the current bottlenecks are order of magnitude larger than this.
Just wondering if, for example, starting a new project with such a struct would be actually worth it. I do worry more about anonymous delegates and memory leaks.
And great content as usual! Though I think having a benchmark for this specific case could prove helpful, as I am sure newer programmers would take a few things as gospel, but it's important to understand the pros and cons.
Profile is the answer each project is different and sometimes the compiler does a lot of optimizations.
Because of how my projects are architecture, I use a lot of delegates and they aren't my bottlenecks.
@@marlonruvalcaba386
Of course, each project is different, and you need to profile to understand your needs.
I doubt any project will ever have this as the actual bottleneck, I am just wondering how much you could actually get from doing this vs the complexity it will add.
ctrl+shift+f: "event" - 113 matches, "delegate" - 34 matches, "Action
Nothing wrong with that many delegates... just review to see if there are any hidden closures!
6:00 - OK FINE! * begins downloading rider*
any other plugins i should start with?
The CognitiveComplexity can be useful, it will tell you if your code is getting overly complex. I also use the Classic UI plugin because I prefer the old look of the IDE. Key Promoter X plugin will help you learn the keyboard shortcuts, but you will want to disable it after a while. If you are coming from VS Code, I would also go to Settings > Keymap and choose "VS Code" there.
@@git-amend Keypromoter is a huge tip thanks!
Nice!
Thanks!
In my experience it's not really going to affect performance unless we're talking allocations in the thousands.
It's like the whole debate on whether or not it's ok to use LINQ, those monads cost.
"compulsory first comment" comment
Nice work!
damn it im second...