Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Unity jobs system for Octree algorithms

Discussion in 'Scripting' started by markbecvar, Aug 29, 2020.

  1. markbecvar

    markbecvar

    Joined:
    Apr 15, 2020
    Posts:
    2
    Hey there,
    I'm currently playing around with Octrees and I started to ran into performence issues.
    After looking around I stumbled upon DOTS with the parallel Jobs system.

    THAT'S SO COOL, I thought...

    The problem I'm facing now... I've done my job changing what's needed to work with jobs BUT, the main thing is that I cannot really pass my OcTree class to the job as a parameter. The class has all what's needed for working with it (i.e. inserting, removing, finding neighbors, etc.).

    Is there any way to use the class with Jobs? I've seen that you should use structs, but they are not particularly great for stuff like Octrees.

    Help is greatly appreciated! Thanks :)
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,635
    You probably built your octree with OOP in mind.
    Using DOTS, or just Jobs, you need switch way of thinking, into Data Oriented Programming.
    So is most likely, you will need rewrite your classes.

    There are many ways you can build your ocree systems, using DOTS.
    I.e. using entities, native arrays, hashmaps.
    Last is mostly the fastest method.
     
    markbecvar likes this.
  3. markbecvar

    markbecvar

    Joined:
    Apr 15, 2020
    Posts:
    2
    Completely right, it is build from ground up with OOP. DOTS was kind of try to optimize further. It feels like multithread shouldn't be as big of a problem these days.

    The "switching the way of thinking" is gonna need some work I suppose. I'll do my homework and try to work DOTS into the thing. Thanks for your insight! :)
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    It is tho. One of my profs always used to say something along the lines of "if you found a way to parallelize any and all workloads by default, you'd be more than just a rich man". There is easily parallelizable workloads.. and then there is the rest of just about everything, which is why most developers dont bother at all, and so many (too many) games run on only one thread, with maybe some minor tasks being outsourced.
    I personally was very impressed with DOTS when i first read about it for this very same reason tho. It gets insanely close to this idea of being able to parallelize pretty much anything - if we are willing to adapt to it and change the way we approach problems accordingly. It's an insanely powerful tool. It's only downside is that it's still changing and that its documentations are a mess (or just non-existant to begin with). Looking forward to its full release. Especially considering they are reworking (or planning to rework) a lot of the Unity core to use DOTS.. which would mean a lot of parallelization by default for Unity based games in the future. Sounds too good to be true imo :D

    Sorry for this little rant, got kinda lost in my thoughts.
     
    markbecvar likes this.