Search Unity

Starting using ECS.. and added 4ms+ to my frame time

Discussion in 'Entity Component System' started by SLGSimon, Jan 12, 2020.

  1. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    So I have spent a few weeks moving a portion of our world objects to ECS (running in hybrid), however when compared to the pure game object version the ECS version is taking 4ms+ extra a frame. I'm still profiling but it looks like this is mostly in the PresentationSystemGroup which is taking 4-6ms, with UpdateDynamicRenderBatches taking most of that time. (This is on 2019.2)

    Is there some kind of checklist I can go through to make sure I'm not doing something stupid? I had a look at the code for Frozen and Static but it doesn't look like they'd be any help. I'm also trying updating to 2019.3 but that hasn't helped.
     
  2. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    The only way you'll see a performance boost WRT rendering is if you have everything set up the same as they do in the Megacity demo: Lots of static entities that share the exact same mesh and material. If your setup doesn't allow for that you're probably better off sticking with built-in/URP/HDRP renderers for now.

    The hybrid renderer is pretty old at this point, as far as I can tell it was built specifically for megacity and isn't really good for general use cases right now.
     
    SLGSimon likes this.
  3. DreamersINC

    DreamersINC

    Joined:
    Mar 4, 2015
    Posts:
    131
    Are you profiling in editor or in actual build? Assuming you are using Windows, what power plan are you run? My latest project runs in editor at about a third of speed of a build. The difference between power saving mode and balance is about 60 fps.
     
    SLGSimon likes this.
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Also, make sure you turn Jobs -> Leak Detection from "Full Stack Traces" to "On" or "Off", disabled the Jobs -> JobsDebugger if you're not using it. And if you're confident in the safety of your jobs with burst, you can disable Jobs -> Burst -> Safety Checks.

    This should get you back quite a bit of perf in the editor in my experience. For some reason, full stack traces is the default and it really should just default to "On".

    One more recent thing that was mentioned somewhere around here. If you're not debugging at all, you can disable editor attaching from the Preferences -> External Tools menu, as this and the burst Synchronous compile settings affect play mode startup.
     
    SLGSimon likes this.
  5. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    I'm profiling on a windows standalone build (with script debugging disabled), on a desktop. We are already CPU bound so the extra time is costing us dearly (and ironically the reason why I want to use ECS).

    I fear @Sarkahn is right, I am working with an online voxel-based world so not really lining up with the megacity "optimisations"...
     
  6. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Even using the "old" renderers you can still get massive performance gains by managing your mesh data inside jobs with burst and using the NativeArray versions of Mesh.Set* functions to push your mesh data. You can even reduce the bottleneck of those functions by using the "advanced mesh api" mentioned here. It's not well documented though so requires some tinkering.
     
    SLGSimon likes this.
  7. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    Your link didn't work, but I assume you're talking about the 2019.3 mesh api additions? Mesh generation isn't a huge problem as what isn't done on another thread can just wait for the next frame if it goes over its time budget. I don't think I'm going to find an extra 4ms there to make it worth it...
     
  8. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    That is what I was referring to, I fixed my link.

    You could always look into the Graphics.DrawMesh* functions. I've found DrawMeshInstancedIndirect in particular can easily render a million+ objects on my machine without breaking a sweat, it's complicated to set up though and requires you to have a reasonable understanding of the graphics pipeline and shaders. You can see us messing with it to render entities in this thread.
     
    5argon and SLGSimon like this.