Search Unity

ECS is just 4 times faster than standard non-ECS approach, is that right?

Discussion in 'Data Oriented Technology Stack' started by Artaani, Mar 23, 2019.

  1. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    410
    Hello. I tried to figure out how much ECS faster than non-ECS methods and turned out it is just 4 times faster.

    Of course, 4 times performance boost it is good result, however everyone talking about ECS so much, so I expected more, maybe 20 times faster or something like that.

    In my opinion, x4 performance boost not worth such complexity of development.

    How I get that result? Let’s see:
    There is an official tutorials where authors compares different methods.
    https://unity3d.com/ru/learn/tutorials/topics/scripting/implementing-job-system?playlist=17117
    https://unity3d.com/ru/learn/tutorials/topics/scripting/using-burst-compiler?playlist=17117

    In the first video he is using standard method via update, as result 18 000 objects have 30 FPS
    In the second video he is using ECS + Burst Compiler, as result 160 000 objects have the same 30 FPS.
    x9 performance boost, Impressive result, however, an example in the first video is very incorrect and non-optimized.

    Let’s do a two things with the first example:

    1. Let’s save a link on Transform component in the variable, so we will not invoke “transform.” several times every frame

    2. Let’s rename void Update () to void ManualUpdate (), after that, let’s add every object in some global List<> and let’s invoke each ManualUpdate () each frame from single void Update () function on the global manager script.

    This is two very simple methods of optimizations which can be implemented super fast and the code still looks simple, however after we do that, performance will be increased 2-3 times.

    After that, if we will compare the first example with the second ECS example, the second one will be not so impressive as before, just 3-4 times performance boost.

    So, the question, in that all capabilities of ECS, or this tutorials is outdated and currently ECS is capable to do much more?
     
  2. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    702
    It is worth mentioning that in the second video the number of objects is limited by the GPU and the CPU is loaded by 30% with 160 000 objects.
     
    Artaani likes this.
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,637
    It is not 4 times faster, it's between 1 and n times faster (often hundreds of times more performant for some things). And it's not just ECS, it's DOTS. Data Oriented Tech Stack. This includes Burst compiler and Jobs (threaded code).

    It's pretty much always going to be more than 4 times more efficient at completing a task, that's for sure, but obviously it depends on the task. You can't say "4 times faster" though as it's illogical.

    Give it a go, it's a brilliant way of coding, but prepare to forget about OOP :)

    For example a task that updates 200,000 objects would be completed in 1ms in DOTS but the same task could take over a thousand millisecs with monobehaviour.

    Bit more than 4. Can be theoretically 1000 times quicker, due to how horrific the memory access abuse is in monobehaviour land. But that is not just because of ECS, it's because of jobs and burst as well that work with ECS. Call it DOTS for short, I guess.

    For example in the megacity demo, it is streaming from HD in 30ms. It does this in background so we don't need to count that. But how long did it take to integrate the loaded data in main thread for rendering and general use? 1-2 ms.

    Can't be done with monobehaviour in 1-2ms no matter how hard you try, it's just an impossibility. It would take 1000 milliseconds, depending how much and what kind of data you'd be streaming in.

    You can brute force a number of problems which give you too much R&D to solve as well. For example you want to render 50,000 small asteroids but they need to be destructable and also bounce off each other? With classic C# in unity you're looking at a cascade of issues, all of which ECS solves so quickly, that it would probably be a lot faster than the elegant solution you'd research. Sometimes brute force is faster than being clever while abusing memory (this is turning out to be the case for most things).

    Way outdated. Moving target :) best way to get up to speed is to start writing code.

    And don't forget to turn off the safety checks ;)
     
    Artaani, RaL and wobes like this.
  4. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    410
    So, if I understood correctly, it just depends on type of task. In that case, it is 4 times faster if I just need to move space ship forward, but for another tasks it could be much faster than x4. Sounds great, especially if it will speed up a complex simulations. I will keep learn it and testing in various tasks.
    Thanks! : )
     
  5. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    242
    You have to be patient with DOTS, it takes time to get used to DOD and forget many principles of OOD. But it is well worth it.