Search Unity

Overhead of not running systems

Discussion in 'Entity Component System' started by Malmer, Apr 12, 2018.

  1. Malmer

    Malmer

    Joined:
    Nov 10, 2013
    Posts:
    18
    Consider a future where there is an ECS-based particle system released by unity (or a popular one on the asset store). To this system many people have developed libraries of systems and componentdata that enhances it to do some really nice things.

    Now if I have a project and I bring in one of those libraries of systems it may contain a whole bunch of componentsystems. But I'm only interested in the SuperCoolParticleTurbulenceSystem and the component data it uses. But now when I build this I will have all the 500 other systems in that library active and running, using up CPU-time. What is the overhead of this? If I have - for some reason - 10 000 ComponentSystems, where actually only around 4 are active at the time as I move around my world. Will that still have a cost to determine if they should be running or not?

    And won't the systems I don't ever use still take up storage/download space and increase compilation times when I deploy?
     
    Krajca likes this.
  2. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    You can always create world with systems you want.
     
  3. Malmer

    Malmer

    Joined:
    Nov 10, 2013
    Posts:
    18
    Yes that’s true. But it will still ship all that code to the client, right? Making the binary larger.
     
  4. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    ComponentSystems have some logic that skips running them in case they don't match any component. You can check
    ComponentSystemBase.ShouldRunSystem
    implementation to get an idea. On top of that, you can explicitly disable the systems via the Entity Debugger, and you can manually enable/disable systems via
    .Enabled
    .

    Not sure if this covers all the possible use cases, but it is probably enough to start.

    On platforms where binary size matters, we run stripping on the code. At the moment, it is not instrumented to understand ComponentSystems and other ECS-related technologies, so some code might be kept alive even if it shouldn't. But moving forward, it is a key principle for us to allow Unity to scale from 50kb games to 50TB games, and the stripping logic will be extended to make sure we cover ECS correctly.
     
    NotaNaN, optimise and FROS7 like this.
  5. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Will it have huge performance and memory penalty if there's a lot of disabled systems?

    I think I need a feature that able to put and run the systems that I want in specified scene. For example, Town scene will only have ABC system and Battle scene will only have DEF system. With that, I no longer needs to put a lot of redundant systems and set them to disabled state. It will also make it easier to setup and do unit testing. But this idea will have collision with ECS World. Currently I haven't figure out a solution to support both.
     
    Zagule likes this.
  6. Deleted User

    Deleted User

    Guest

    You can disable automatic world creation and create your own world where you can specify what systems get added.
    To disable automatic world creation you need to define "UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP" (Edit->Project Settings->Player->Scripting Define Symbols).
    I wrote a small abstraction layer for custom worlds https://bitbucket.org/element_wsc/unity-ecs-world-bootstrapper/src/master/
    You can attach GenericBootstrapper to a gameobject and choose what systems get added through the inspector or you can override BootstrapperBase if you prefere to do it in code
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Our goal is very much that you can have 1000s of systems that have no active entities, without worrying about performance or memory consumption. Thats why we have those early outs.
     
    NotaNaN, 5argon, Zoey_O and 2 others like this.