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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Performance issue

Discussion in 'Entity Component System' started by YuriyVotintsev, Apr 26, 2022.

  1. YuriyVotintsev

    YuriyVotintsev

    Joined:
    Jun 11, 2013
    Posts:
    91
    I have this small system. But this system takes 0.100ms of time every frame. There are only 2 entities that match query. I do profiling wrong, or entities package without burst are so slow? Or math methods are slow? What is wrong with this code?
    0.1ms is too much for this simple code. With only 60 of such small systems I will spent all of frame budged. (6ms for scripts and 5ms for rendering for 90fps on oculus quest 2).
    Unity 2020, entities 0.50, Android (Oculus Quest 2).

    Screenshot 2022-04-26 135837.jpg
     
    miknios likes this.
  2. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    at the moment it is known, that ECS is still quite "slow" with a few entities, but that should change (1.0?)
    In the editor everything runs slower.
    Is there a reason why you run without burst? Burst is precisely there so that it gets faster and at first glance I don't see why the code can't run without burst.
     
    MNNoxMortem and Anthiese like this.
  3. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    910
    First of all, use Burst! Entities without Burst is not that great.
    I don't see any managed types so I don't understand why you use WithoutBurst.

    Second, it's important to turn off Safety checks in Jobs->Burst. Also turn off Leak Detection. With these turned off you have nearly the same timings as in a build.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Please don't use screenshots of code. It's low effort.
     
    MNNoxMortem and Anthiese like this.
  5. YuriyVotintsev

    YuriyVotintsev

    Joined:
    Jun 11, 2013
    Posts:
    91
    This system takes 0.100ms in build on Android. So I think Leak Detection and Safety checks are disabled in build. I'll check this system with burst, but it still is very strange that without burst it takes so many time.
     
  6. slims

    slims

    Joined:
    Dec 31, 2013
    Posts:
    86
    You should be using burst but .1ms is insanely slow for this calculation for 2 entities, something else is up.

    Do you see it taking .1ms on the worker in the profiler? The entity debugger can be somewhat misleading since it will accumulate time spent in other jobs at sync points and report that time on whichever job the sync point happens.
     
  7. YuriyVotintsev

    YuriyVotintsev

    Joined:
    Jun 11, 2013
    Posts:
    91
    This number is from profiler, not from entity debugger.
     
  8. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    944
    There's no point of not using Burst whenever you can, unless you're debugging.
     
    Krajca, Anthiese and MNNoxMortem like this.
  9. miknios

    miknios

    Joined:
    Sep 12, 2017
    Posts:
    6
    Why you're all pointing on not using Burst? We can agree that it's faster with burst, but this execution time is still very high even without it.
     
  10. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    910
    It's not slow for Mono C#.
    There's quite a bit of hefty arithmetics involved. Many of which Burst can take advantage of. There's also overhead that's not apparent like the EntityQuery. But really, most is the heavy mathematics being used. You're really underestimating unoptimized matrix multiplications.

    If you're so inclined of this being slow. Why not just write the same loop of 2 entities out in classic MonoBehaviour and report the numbers. If you get it down factor 5-10x to 0.01 - 0.05 I'd say there's an issue but I doubt that.

    edit: Just realized @miknios is not OP. Point still stands.
     
    MNNoxMortem likes this.