Insanely FAST Spatial Hashing in Unity with Jobs & Burst

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

КОМЕНТАРІ • 66

  • @git-amend
    @git-amend  Місяць тому +9

    Happy Sunday! 😊 Thanks for watching, and if you found the spatial hashing concept helpful, don’t forget to LIKE and subscribe and drop your questions below!

  • @hop3studio511
    @hop3studio511 Місяць тому +14

    Your tutorial release schedule is on fire 🔥 bro, and not just fast, but advanced.... Glad we have you as unity tutorial channel, keep it up

  • @selmansavas586
    @selmansavas586 Місяць тому +7

    As always, right when i need something like this ❤ There is no other like your content, the topics, the quality, the soothing voice, its just ❤🤌
    Thank you for the awesome content 🎉🎉

    • @git-amend
      @git-amend  Місяць тому +1

      Thanks for watching and the kind words!

  • @Anvelir
    @Anvelir Місяць тому +3

    OMG. This is exactly what I needed for my Voxel systems.

    • @git-amend
      @git-amend  Місяць тому +1

      Awesome! Glad to hear that!

    • @Anvelir
      @Anvelir Місяць тому +1

      ​@@git-amend I tried to mess up with OctTrees, not only from your last video. But I noticed they have problem - extended, long objects are creating very huge, inperformant tree.
      And also it is hard to control, add and remove objects - you have to debug it in the recursion, trying to catch the error or spontaneous nulls...
      This algorithmic data structure you brought saved my nerves very much :)

  • @silchasruin4487
    @silchasruin4487 Місяць тому +3

    Love the video! I love to actually see these optimization techniques, tools and experiments along with the stress tests behind them. Especially when optimization is not a huge focus on game dev and tutorial channels, since that can be the achilles heel of many noob game devs. I remember starting out, following a tutorial thinking this will be the foundation for my procedural open world game aaaand you realise you can't do anything else with the project. Have a good one, looking forward to the next one!

    • @git-amend
      @git-amend  Місяць тому +2

      Thank you! Glad you enjoyed it!

  • @techdave99
    @techdave99 Місяць тому

    Only part way through the video and already know that I will need to watch a few times. Looks like something I can use, once I understand it.

    • @git-amend
      @git-amend  Місяць тому

      Yes, spatial hashing has many applications! You got this!

  • @starplatinum3305
    @starplatinum3305 Місяць тому +1

    I just love optimizations bro
    Who let him cook 🗣️🔥🔥🔥

  • @TrentSterling
    @TrentSterling Місяць тому

    Huge area of interest for unity devs who want to make a game that doesnt explode potatos! Love it!

  • @ankitwarkade6920
    @ankitwarkade6920 Місяць тому

    I was eagerly waiting for this☺

    • @git-amend
      @git-amend  Місяць тому

      Awesome, hope it helps you out!

  • @rambertoeco8930
    @rambertoeco8930 Місяць тому

    Cool stuff and all explained so well! I'd love to learn more about how the multithreaded code is actually used by professionals. Thanks for this video!

    • @git-amend
      @git-amend  Місяць тому +4

      I'm sure we'll talk more about that soon on the channel!

  • @isleeg
    @isleeg Місяць тому

    Now you changed the saturation of the font color, I really prefer the the more saturated font color that you had in your previous video!

    • @git-amend
      @git-amend  Місяць тому

      Interesting, I was wondering if anyone would notice. Thanks for the feedback.

  • @bodardr
    @bodardr Місяць тому +1

    Hey huge fan of your videos, your code quality is simply the best out there. Quick question, wouldn't Hashsets save us from doing a binary search to get the proper cell?

    • @git-amend
      @git-amend  Місяць тому +1

      Good question. In this case, we're not just doing a simple lookup to check if a particle exists in a specific cell, but rather we need to retrieve all particles that belong to the same hashed grid cell. Since HashSets don't allow for storing multiple values per key (like particles in the same grid cell), they'd be ineffective here.

    • @bodardr
      @bodardr Місяць тому

      Oh right, of course! And this allows us to get multiple and is of log(n) complexity. I missed out on that on the first watch, thanks!

  • @Thimas
    @Thimas Місяць тому

    Thank you so much for this tutorial! I just started using ECS with Jobs a month ago, but I had a hard time figuring out how to use Jobs with normal MonoBehaviors and such outside of the Entities Systems, so this really helped me. Would love even more of this style of performance-oriented videos. Just for curiosity, how do you paste all those lines of code so quickly in your tutorials - do you have another IDE open with it on your other monitor or some kind of Clipboard addon? Looks very smooth!

    • @git-amend
      @git-amend  Місяць тому

      Glad you found it helpful! The pasting is just the magic of editing!

  • @nickolasbrown2260
    @nickolasbrown2260 Місяць тому

    We need more dots tutorials from u . Its soo hard to start with 😫

    • @git-amend
      @git-amend  Місяць тому

      Yup, one of these days we'll work up to some full blown DOTS.

  • @ThorBonde
    @ThorBonde Місяць тому

    what a delicious guide, please make ore guides on unity dots, jobs and burst

    • @git-amend
      @git-amend  Місяць тому +2

      Yup, one of these days. We'll see how many subscribers are interested in Jobs and Burst first I suppose.

    • @SA-lk6lv
      @SA-lk6lv Місяць тому

      @@git-amend An in depth video just focusing on Jobs & Burst would be great bro

  • @frontalachivment3604
    @frontalachivment3604 Місяць тому

    Another day, another good video above youtube unity level.

  • @Flaming_Hot_Beans
    @Flaming_Hot_Beans Місяць тому

    Awesome, would you consider doing a video on creating super efficient voxel / Minecraft type system in unity?

    • @git-amend
      @git-amend  Місяць тому +1

      Yeah, a few people have asked already. I'm giving it a bit more thought...

    • @Flaming_Hot_Beans
      @Flaming_Hot_Beans Місяць тому

      @@git-amend oh that's great, don't worry if it's a bit out of the scope of the channel. Great videos and content 👍. All the best.

  • @ZombieChicken-X
    @ZombieChicken-X Місяць тому

    Oh look at that I just dropped a comment on the previous video about some possible topics and then a video drops on Jobs and Burst! sweet!

  • @yelo2k134
    @yelo2k134 Місяць тому +4

    One thing to mention is that you could use TransformAccessArrays to read and write transform data and skip the step of converting it to native structs, as well as having to write to the transform once the job is completed. Also, it would be great if you showed the profiler at the end to show how performant the jobs are, in small cases like this you're probably spending more time rendering the spheres, accessing their material properties and changing their transforms. If you were to bump up the sphere count to 5000-10000 then you'd probably only spend 5% of the frame calculating the job.

    • @git-amend
      @git-amend  Місяць тому

      Great point! Using TransformAccessArray is a solid optimization suggestion for directly reading and writing transform data without the need for conversion, especially for jobs that manipulate a lot of transforms. I’ll definitely consider incorporating that in a future video-thanks for bringing it up!

    • @zorglug
      @zorglug Місяць тому

      TransformAccessArray has a ton of weird quirks IIRC, like not being able to process sibling Transforms in parallel and you have less control overall. It also contains the full matrix data of the transform, which is likely to be less cache efficient than custom data (speaking of which, I would split position from velocity and radius for that same reason since only one of the particle jobs uses the latter two). My hunch (haven't tested) is that it's better to keep the struct data for the updates and sync back using TransformAccessArray in a non-parallel Burst job; but I could be wrong about this. Definitely worth profiling! I'll try to remember to test when near my computer.

    • @zorglug
      @zorglug Місяць тому +1

      Quick update: it doesn't change too much performance-wise with this setup and TIL that there is no easy way to do transform jobs single threaded. The main advantage I saw is that updating a bunch of float3 is a bit faster and you can schedule the transform update in parallel with the hashing and querying. All of the time is still lost on rendering anyway. But I got the full jobs time from 0.6 ms to 0.45 on my machine with 10k particles. Biggest gain was removing the custom sort job and using hashAndIndices.SortJob(). I also made more gains by changing the batch sizes than by futzing with the TransformAccessArray stuff. YMMV, of course.
      *edit: Forgot to mention that both versions using TransformAccessArray were ~20% faster than when not using it. My point was that separated or not didn't make a huge difference.

  • @-moristan109
    @-moristan109 Місяць тому +2

    As always add a like first then enjoy the content

  • @AryanSingh-cw6ce
    @AryanSingh-cw6ce Місяць тому

    hi, Its very good video , easy to understand as always ,Question: Please tell how can i check how much memory i have and is utilizing by using burst compiler as it uses direct memory allocation ? Never used it before and it's still scary for me right now 😊 .

    • @git-amend
      @git-amend  Місяць тому

      Maybe we'll do another video on memory in the near future...

  • @techdave99
    @techdave99 Місяць тому +1

    I have this crazy idea of trying to combine the jobs and burst used here with the Octree video of last week. Don't know if it's needed or useful though.

    • @git-amend
      @git-amend  Місяць тому

      Well, the useful thing about Octrees is that you can disregard huge areas of the 3D space, so it's not quite as useful as with a discrete grid. But it can still be done of course.

    • @techdave99
      @techdave99 Місяць тому

      @@git-amend Ok. That makes sense. Thanks.

  • @damonfedorick
    @damonfedorick Місяць тому

    Nice!

    • @damonfedorick
      @damonfedorick Місяць тому

      769,721 views, almost 1 Million.

    • @git-amend
      @git-amend  Місяць тому +1

      Hard to believe... maybe before the end of the year...

  • @lavatasche2806
    @lavatasche2806 Місяць тому +1

    Hi cool video. It would be nice to display the fps alongside, since this is a technique for better performance.

    • @git-amend
      @git-amend  Місяць тому

      Thanks for watching!

  • @turkaytandogan439
    @turkaytandogan439 14 годин тому

    Sir i am making 3d mobile game that a lot of enemies following player so i wanna make enemies avoid eachother certain distance. Can i make with this system ? Can you give me some info please if its possible ?

  • @SeriousNeko
    @SeriousNeko Місяць тому

    Is Binary Search faster for this case than a Hashmap?

    • @git-amend
      @git-amend  Місяць тому

      I think this would be dependent on your use case, and if you wanted to go with a Hashmap you could consider using the NativeMultiHashMap struct.

  • @ferdinandkasangati5089
    @ferdinandkasangati5089 Місяць тому

    Hey my brother, I felt completely lost 😂👌
    Could really be helpful having an Optimization video and Burst/Jobs tutorials in simple stuff first then we'll know how to implement the knowledge in our programming life

  • @GuiLei010
    @GuiLei010 Місяць тому

    🖥

  • @julianemery718
    @julianemery718 Місяць тому

    Didn't Unity do some really shady stuff recently?
    Something about changing their rules so for any game made with it, the devs of said game had to pay unity a little bit of money per download?
    Not only that, they made it retroactive so even before the rule change the devs had to pay for every download of their game, period.

    • @git-amend
      @git-amend  Місяць тому +1

      Unity no longer has a runtime fee, they've thrown that idea out.