Fix Closure Issues in 10 Minutes and Boost Performance

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 37

  • @git-amend
    @git-amend  День тому +14

    Happy Holidays! Hope everyone is having a break of some kind! Link in description to Blog post about Heap Allocations Viewer! 👍

  • @klevialushi571
    @klevialushi571 2 хвилини тому

    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!

  • @dezikso9358
    @dezikso9358 День тому +6

    Awsome as always. Have you considered making a series in which you make a simple game architecture and explain how different patterns coexist together?

    • @git-amend
      @git-amend  День тому +9

      Yes, I have. It's a good idea and probably something we can do in the coming year!

    • @johnanthony44
      @johnanthony44 17 годин тому

      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.

  • @jackieczech1777
    @jackieczech1777 День тому +2

    Adam, Thank You for all the great videos and sharing your knowledge. Please keep it up! It's awesome!

  • @raymk
    @raymk 12 годин тому

    Another tool for my arsenal. THANKS!!!

  • @nexgen.graphics
    @nexgen.graphics День тому +6

    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
      @git-amend  День тому +2

      Thank you so much for the kind words! I’m really glad you found the explanation clear and helpful!

  • @dragonsnackproductions
    @dragonsnackproductions День тому +2

    I will say it as simple as I can -> "Best YT content GOTY+ Award" :D thank you!

    • @git-amend
      @git-amend  День тому +1

      Wow, thanks!

    • @dragonsnackproductions
      @dragonsnackproductions День тому

      @@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!

  • @kpm25
    @kpm25 День тому

    Thanks as always!!

  • @정동우-n2x
    @정동우-n2x День тому +1

    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.

    • @정동우-n2x
      @정동우-n2x День тому

      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?

    • @git-amend
      @git-amend  День тому +1

      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.

    • @정동우-n2x
      @정동우-n2x День тому

      @@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.

    • @정동우-n2x
      @정동우-n2x День тому

      @@git-amend You have a GOOOD talent who can easily explain it to a bad-headed person like me.

  • @leos-clockworks335
    @leos-clockworks335 День тому +1

    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.

    • @marlonruvalcaba386
      @marlonruvalcaba386 День тому +1

      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.

    • @leos-clockworks335
      @leos-clockworks335 17 годин тому

      @@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.

  • @gladiko2364
    @gladiko2364 День тому

    ctrl+shift+f: "event" - 113 matches, "delegate" - 34 matches, "Action

    • @git-amend
      @git-amend  День тому

      Nothing wrong with that many delegates... just review to see if there are any hidden closures!

  • @Fitz0fury
    @Fitz0fury День тому +1

    6:00 - OK FINE! * begins downloading rider*
    any other plugins i should start with?

    • @git-amend
      @git-amend  День тому +2

      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.

    • @Fitz0fury
      @Fitz0fury День тому

      @@git-amend Keypromoter is a huge tip thanks!

  • @damonfedorick
    @damonfedorick День тому

    Nice!

  • @Bankoru
    @Bankoru День тому

    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.

  • @Fitz0fury
    @Fitz0fury День тому

    "compulsory first comment" comment