Overhead of not running systems

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?

1 Like

You can always create world with systems you want.

Yes that’s true. But it will still ship all that code to the client, right? Making the binary larger.

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.

3 Likes

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.

1 Like

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 Bitbucket
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

4 Likes

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.

5 Likes