EasyEcs

FAQ

Short answers about using EasyEcs in game servers, simulations and real-time .NET backends: allocations, threading, Unity, Native AOT, saves and comparisons.

Is EasyEcs only for game servers?

No. EasyEcs is a C#/.NET 10 ECS library for workloads that repeatedly update many entities: game servers, simulations and other long-running real-time backends. A world holds plain component data; systems process matching entities on a tick. The library does not assume that an entity is a player or that a tick comes from a game. For example, a service can model moving vehicles, devices or workers as entities and run movement, status and expiry systems over them.

The architectural fit matters more than the label. Use an ECS when the same operations run over many changing items and predictable hot-path costs matter. A conventional database-backed CRUD service with little shared per-item work usually has no need for an ECS. EasyEcs supplies the world, queries, systems and state management; you supply the transport and host. The ASP.NET Core and Worker hosting guide shows one way to connect HTTP requests to a world without touching it from request threads.

Is EasyEcs production ready?

EasyEcs is published on NuGet under the MIT license and built for long-running .NET servers. What backs it up, in the repository:

  • Hundreds of NUnit tests, one file per feature, including allocation tests with a budget of 0 bytes, generator and analyzer tests, and a battle server that runs every feature at once (the example).
  • BenchmarkDotNet suites for every feature and against Friflo.Engine.ECS, Arch and DefaultEcs, each result checked in setup (Performance).
  • CI that builds, tests, runs every sample and example, compiles the C# snippets of these docs and checks the generated API reference.
  • An analyzer that rejects the design mistakes an ECS makes easy (EECS002 to EECS034), with code fixes.

What to weigh: it targets net10.0 only, the API changes between minor versions while it matures (4.0 to 4.1 renamed and removed a few members, and in 4.2 reading a singleton that was never added throws; the migration guide lists each change), and the changelog shows what each release changed.

Does EasyEcs allocate?

Not on hot paths. Queries, iteration, component access, [ForEach] systems, parallel runs and structural changes allocate nothing once the world is warmed up (its tables, query cache and pools have reached their peak sizes). The headline server tick of 100,000 entities takes 1.72 ms and allocates 0 B.

BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.

What allocates, on purpose: creating a world, the first entity of a new component set (a new table), the first use of a query shape, a table or a DynamicBuffer<T> growing past its capacity, and cold tools such as Describe. InitialEntityCapacity, EnsureCapacity<T1, …, Tn>(count), EnsureCapacity(prefab, count) and bag.EnsureCapacity(n) move growth out of the tick.

Is it thread-safe?

The rules are explicit and short (D13):

  • A world has one owner thread. Its systems, queries and component reads and writes run there. On a server, run one world per thread (one per map, zone or match): worlds share nothing, so they scale across cores without locks.
  • Structural changes belong to the owner thread. Adding or removing components and creating or destroying entities check a plain owner flag: a change made inside a parallel stage, a parallel [ForEach] or a pass that promised none throws instead of tearing the tables. The analyzer reports the off-thread changes it can see (EECS013, EECS014).
  • The parallelism EasyEcs adds is checked. WorldOptions.ParallelSystems runs systems together only when their generated access does not conflict, with the same result as running them one by one; a [ForEach(Parallel = true)] method must change no structure and write no singleton (EECS010).
  • Input from other threads (network, IO) goes into a queue of yours that one system drains on the owner thread.

Never keep a ref across an await: keep the Entity and get the component again. More in Threading and ref and await.

How do I run EasyEcs in ASP.NET Core or a Worker Service?

Give the world one owner: a BackgroundService that builds it, calls world.Update() on a PeriodicTimer and saves it when the host stops. Request handlers never touch the world: they write requests into a bounded Channel<T> that a system drains each tick (with a TaskCompletionSource for the reply), and read an immutable status the world publishes. A request for one entity (an actor, a player) is handled on that entity, on the owner thread, with entity.Run(ref job, filter): one lookup for all the components the job needs, and false when the entity is gone or does not match (One entity: entity.Run). No hosting package is needed; Hosting in a .NET server has the whole server.

How do I test a system?

Build a world in the test, add the system and the entities and singletons it needs, call world.Update() and assert on the components. Systems never call each other, so there is nothing to mock; share the server's setup method so the test runs the real order. A zero-allocation budget is one more test: count GC.GetAllocatedBytesForCurrentThread() around warm updates (Testing systems).

How should I structure an EasyEcs project?

The way dotnet new easyecs lays it out: components in Components/ (one file per thing they describe, plain data), one system per file in Systems/ with one job each, and Program.cs as the host that builds the world, sets the singletons, adds the systems in one place and runs the loop. Groups give each cadence its own update, input from other threads goes through a mailbox (a queue in a singleton), and --tests adds one test file per system (Structuring a real project).

How do I debug an ECS world?

Ask the world: world.Describe() lists the tables with their components, entities and bytes, entity.Describe() returns an entity's component values (the debugger shows them too when you expand an Entity), system.Stats times every system with WorldOptions.MeasureSystems, and system.Error keeps the exception of a system switched off by SystemErrorPolicy.Disable. Read them on the owner thread between updates (Debugging and diagnostics).

Can I use EasyEcs with Unity or Godot?

No. EasyEcs targets net10.0 only: it relies on C# 14 extension members, Vector256 / Vector512, columns on the pinned object heap and current JIT behavior (D15), which Unity's runtimes do not offer. Godot is not a tested or supported target either: EasyEcs is built for servers and has no engine integration. The usual setup is EasyEcs on a .NET 10 game server and the client engine's own tools on the client; EasyEcs and Unity Entities says how the two models differ.

How does EasyEcs compare with Arch, Friflo.Engine.ECS and DefaultEcs?

All four are C# ECS libraries; they differ in what they do for you and what it costs. EasyEcs generates the loops from [ForEach] methods, applies structural changes immediately (no command buffers), tracks changes and removals as data, and checks the ECS rules at compile time. In 37 head-to-head benchmarks (BenchmarkDotNet, each library doing the same work its own idiomatic way), EasyEcs is faster in 24, within the measurement error in 11 and slower in 2. Its biggest leads:

Feature by feature: how many times longer the next-fastest library takes

Each comparison does the same work in Friflo.Engine.ECS, Arch and DefaultEcs, each library's own idiomatic way, with identical results checked in setup. A bar is the fastest other library's time over EasyEcs' time (log scale).

Save 10,000 entities and load them back30× · DefaultEcsAdd a component to 100,000 entities by query, then remove it15× · ArchSpawn 10,000 entities beside 100,000, then destroy them2.75× · FrifloQuery 100,000 players by value: a rating range, zone sums2.49× · FrifloCreate 1,000 parent-child squads, destroy them in cascade2.35× · FrifloCount 100 inventories through an index (1 item traded)1.97× · DefaultEcs1×2×5×10×20×Its time ÷ EasyEcs' time (log scale)

BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.

Data table
What is measuredEasyEcsNext fastestvs EasyEcs
Save 10,000 entities and load them back146 μsDefaultEcs 4.33 ms30×
Add a component to 100,000 entities by query, then remove it78.7 μsArch 1.21 ms15×
Spawn 10,000 entities beside 100,000, then destroy them138 μsFriflo.Engine.ECS 380 μs2.75×
Query 100,000 players by value: a rating range, zone sums127 μsFriflo.Engine.ECS 317 μs2.49×
Create 1,000 parent-child squads, destroy them in cascade452 μsFriflo.Engine.ECS 1.06 ms2.35×
Count 100 inventories through an index (1 item traded)425 nsDefaultEcs 838 ns1.97×

On the full server tick the four are closer:

One server tick of 100,000 entities: EasyEcs vs Friflo, Arch and DefaultEcs

The same simulation ported to each library's fast path, with identical results checked in setup. Shorter is faster; the badge is the time relative to EasyEcs and the memory allocated per tick.

  • EasyEcs
  • Other libraries
EasyEcs 4.60 B per tick1.68 msFriflo.Engine.ECS 3.61.08× · 0 B per tick1.83 msArch 2.13.4× · 535 KB per tick5.76 msDefaultEcs 0.173.7× · 60.9 KB per tick6.24 ms0.00 ns1.00 ms2.00 ms3.00 ms4.00 ms5.00 ms6.00 msTime per tick

BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.

Data table
LibraryTimevs EasyEcsAllocated
EasyEcs 4.61.68 ms1.00×0 B
Friflo.Engine.ECS 3.61.83 ms1.08×0 B
Arch 2.15.76 ms3.4×535 KB
DefaultEcs 0.176.24 ms3.7×60.9 KB

Every result, with where another library is faster and why: Comparison, and the pages vs Arch, vs Friflo and vs DefaultEcs.

How do I save a world?

Three tools, for three needs:

NeedCallPage
Undo, rollback, prediction, replays in memoryworld.Capture() / world.Restore(snapshot)Snapshots
A whole world to disk, a database or another processworld.Save(output) / world.Load(bytes)Saves
A group of entities (a player and what it owns) to another world or serverSaveEntities / LoadEntities, MoveEntitiesMigration and unloading
The durable part of an actor, restored onto its entity without counting as a changeSaveEntities(output, ids, set) / LoadEntitiesInto(bytes, entities, markWritten: false)Records
using System.Buffers;

var output = new ArrayBufferWriter<byte>();
world.Save(output);              // entities with their ids, components, singletons
world.Load(output.WrittenSpan);  // EntityIds stored in components still point at the same entities

Saves are built in from 4.1 (D9): unmanaged components are written as their raw rows with a hash of their fields, so a changed struct is detected at load; managed components, singletons and the unmanaged components marked [NinoType] go through Nino. Types are recorded by their Nino type id, so a load skips a component the process no longer has.

Can I hot-reload game logic?

Yes. Load your systems and components from a plugin assembly in a collectible AssemblyLoadContext. To replace it, save the world, call world.RemoveTypes(assembly) (its systems, singletons, indexes and components leave the world; the entities stay), unload the context, load the new version and Load the save: types are saved by type id, so the new version's components take the values (D17). The HotReload sample does it end to end and checks that the old assembly was collected.

Does EasyEcs work with Native AOT?

Yes. EasyEcs.Core is marked IsAotCompatible, so the trimming and AOT analyzers run on every build of the library, and the generated code calls your methods directly (no reflection on hot paths; D16). A program built on it publishes with PublishAot without warnings and runs: CI publishes the battle server example, with tracked components, disabled components and saves, as a native executable with warnings as errors and runs it. One limit: a generic system closed only by another assembly falls back to MakeGenericType, which Native AOT cannot do (D20). Deploying a server: hosting.

Why are there no events?

Nothing calls your code when a component is added, removed or written (D1). A callback runs inside another system: it hides the control flow, can re-enter the code that raised it, and its reads and writes are invisible to the scheduler, so systems could not run in parallel safely. What an event would say is data instead:

The event you wantWrite it as
An entity died, others should reacta Dead tag; the systems that care filter [With<Dead>]
A component was changedmark it ITrackChanges; the consumer takes [Changed<T>]
A component was removed (a buff expired)mark it ITrackChanges; the consumer takes [Removed<T>]
A one-off message (a hit, a player input)an entity holding the message, destroyed after its readers ran
Input from another threada queue that one system drains on the owner thread
public record struct Hit(EntityId Target, int Damage) : IComponent;    // a message is an entity

public class ApplyHitsSystem : EcsSystem
{
    [ForEach]
    static void Apply(in Hit hit, World world)
    {
        if (!world.TryGetEntity(hit.Target, out var target)) return;    // the target is gone
        ref var hp = ref target.TryGetRef<Health>(out bool found);
        if (found) hp = hp with { Value = hp.Value - hit.Damage };
    }
}

[UpdateAfter<ApplyHitsSystem>]                                          // after every reader
public sealed class ClearHitsSystem : EcsSystem
{
    protected override void OnUpdate() => World.DestroyEntities<Hit>(); // every message, one pass
}

The order of effects is the order of the systems, visible in one place; the generator knows what every system reads and writes; tests and snapshots see the "events", because they are data.

Why are there no command buffers?

Structural changes apply at once, also in the middle of a pass (D2): a removed row becomes a tombstone while the pass runs and the pass never sees rows shift, so code reads as it is written and no second, deferred version of the world exists. Parallel jobs make no structural change; a system after them, on the owner thread, makes it from the data they wrote (D3). What a pass sees when you change structure inside it: Structural changes.

How do I order systems?

Systems run in the order you register them. To make one depend on another, name the dependency: [UpdateBefore<T>] or [UpdateAfter<T>] on the class moves only that system within its group, so adding one ordering never reshuffles the others (D5). A cycle throws in AddSystem and is reported by EECS019 when the analyzer can see it. There are no integer priorities: Priority was removed in 4.1. Systems that run on a different cadence go into a system group updated by its own call, or set UpdateInterval and UpdatePhase.

How do I change a component?

Through a ref. In a [ForEach] method, a ref parameter is a write and in is a read:

public record struct Poison(int DamagePerTick) : IComponent;
public record struct Mana(int Value) : IComponent;

public class PoisonSystem : EcsSystem
{
    [ForEach, Without<Dead>]
    static void Hurt(ref Health hp, in Poison poison) => hp = hp with { Value = hp.Value - poison.DamagePerTick };
}

Outside systems:

entity.Mana.Value -= 10;                                     // untracked: the generated property is a ref
ref var poison = ref entity.Poison;                          // keep the ref for several writes
poison.DamagePerTick = 3;
ref var mana = ref entity.TryGetRef<Mana>(out bool found);   // when the entity may not have it
if (found) mana.Value += 5;
entity.Set(new Position(0, 0), new Velocity(1, 0));          // add or replace several in one call: shorter, same cost
foreach (var item in world.Query<Position, Velocity>())
    item.Position.X += item.Velocity.X;                      // refs into the row

Three mistakes to avoid:

  • var hp = entity.Health; hp.Value--; changes a copy. Keep a ref var.
  • Read with in, not ref: every ref access to an ITrackChanges component counts as a change, so replication would send rows nobody changed. The generated property of a tracked component is read-only for this reason; entity.WriteX() is the write.
  • Change a collection inside a component through a ref to the component, never through in: change tracking and the scheduler would miss it (EECS011). For a list per entity, use a DynamicBuffer<T>.

How many component types can a world have?

Up to 65,536 component types per process (component bits are 16-bit). The first 256 are tested with one Vector256 instruction per table; the rest live in an overflow that is allocated when a table is first built, never on a hot path (Architecture).

Do systems have to be partial?

No. The generator writes each system's jobs in a file class of its own and calls your [ForEach] methods, private or not, through [UnsafeAccessor], which compiles to a direct call (D16). A system is an ordinary class, and generated members never collide with yours. partial still compiles.

Edit on GitHub

Last updated on

How is this guide?

On this page