sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.08k stars 1.11k forks source link

How performant is Entitas vs Unity ECS and Classic Unity? #910

Closed Trithilon closed 1 year ago

Trithilon commented 5 years ago

Hi, I am trying to make a multiplayer game with a dedicated server (most likely deterministic lockstep) and plan to use ECS since I am getting unreasonable CPU usage on my current implementation (Just a 6 player headless gameserver sucks up 6-7% CPU on a quadcore machine at 60 FPS!). My plan is to write my server in dotNetCore for that sweet linux/container friendly low footprint environment and write a custom view/wrapper for the simulation in Unity.

To my knowledge, what makes vanilla unity slow is how bulky each gameobject is. Since Entitas uses Gameobjects to represent entities in Unity, will I be losing a whole lot of performance when I have a lot of entities? Or is there a more "PURE" version of ECS using Entitas in Unity?

FNGgames commented 5 years ago

Entitas doesn't use GameObjects to represent entities except for the "Visual Debugging" feature which you wouldn't be using on a server. Entitas is entirely a pure C# library and has no dependence on the unity engine except for optional extensions and utilities.

Unity's "slowness" comes from a variety of factors. A big one is the interface between native C++ code in the engine and the C# code you write as a developer. Every time you call into a transform to get / set position for example, behind the scenes, the engine is calling into the native code and copying data back into the C# MonoBehaviour wrappers. Of course in an entitias application it all stays in the managed side and that slowdown is removed. There's also messaging (unity's string-based private-method calling systems that are responsible for calling methods like Start() and Update(). And the GameObject class is heavy as you said.

Entitas is good solution for server applications I think, you can make a tiny binary, you can manage memory allocation easily. Having thousands of entities is not an issue.

hyperhuzaifa commented 5 years ago

Thanks for the response. So, the fundamental idea behind ECS performance is getting those cache hits, right? I dont know how CPU cache functions, but will running too many ECS programs together simultaneously saturate the few MB of cache and not let all of them run at full speed? Or is it just supposed to give you top notch performance when you are running only one ECS base application which can hog all the cache?

FNGgames commented 5 years ago

Honestly here the performance is just coming from it being a really light framework with light data classes (components) that are smartly pooled. It allows you to design a data model with a really low memory footprint and do most if not all of your allocation at the start of your application, reducing GC pressure. Idk to what extent the cache coherecy is adding to that, i havent profiled for this.

SupinePandora43 commented 4 years ago

Classic Unity "GameObject" (Object Oriented):

Pluses:

Minuses:

ECS (Data Oriented):

Pluses:

Minuses:

pepoon commented 3 years ago

Hey guys.. Sorry to comment on an old topic but I would like to know what do you thing about this question..

Should I use Unity ECS or Entitas for a rts simulation shared between client and server..

I'm wondering what is the best approach to develop a rts simulation that needs to run on client & server side..

So my question is.. Should I develop the RTS simulation as a pure c sharp dll, and share it with unity and the backend? This approach will make me use Entitas framework.

Or should I use Unity ECS then create a server build? I'm lost here.. Imagine I want to develop a Clash Royale game. Clash Royale game has 'the 'Home" screen where you collect boxes and then the "Battle"(the simulation)..

So what would be your approach? Thanks.