Performance guide
How fast EasyEcs is and how to keep your code fast: measured server ticks, the cost of each iteration API, a checklist and every BenchmarkDotNet result.
EasyEcs is built for a server tick that runs every few milliseconds for months: the regular way of writing a system is already a generated, inlined struct job, and a busy world allocates nothing per tick. This page shows what that costs on a real tick, which API to pick for each loop, the rewrites that pay when a system shows up in your timings, and every benchmark behind those numbers. How the library gets there is on Why EasyEcs is fast.
Save 10,000 entities and load them back, vs DefaultEcs
30×faster- EasyEcs146 μs
- DefaultEcs4.33 ms
One server tick
1.72msFour worlds, one thread each
924μsAllocated per tick
0BBenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
The headline ticks
WorldSimulationBenchmark is one tick of a busy MMO-style world, not a toy loop: 30% players, 70% NPCs and
projectiles on top. One tick runs movement (skipping Stunned and Dead), an area-of-interest grid, combat that
adds Burning and Stunned at random, status expiry that removes them, death (a Dead tag and a statistics
singleton), respawn (dead NPCs replaced, dead players revived in place), and projectiles spawned by about 5% of the
players and expired after 20 ticks. Setup checks that the world is busy: hits, deaths, spawns and grid changes all
happen.
| Benchmark | What it runs | Time per tick | Allocated per tick |
|---|---|---|---|
WorldSimulationBenchmark | one world, 100,000 entities | 1.72 ms | 0 B |
MultiWorldBenchmark | four worlds of 25,000, one thread each | 924 μs | 0 B |
BattleServerBenchmark | the battle server: every feature at once | 2.97 ms | 0 B |
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
The four worlds of MultiWorldBenchmark are the layout recommended for a server: one world per map or zone, each
owned by one long-lived thread.
Against other libraries
The same work ported to Friflo.Engine.ECS, Arch and DefaultEcs, each library its own idiomatic way, with identical results checked in setup: EasyEcs is faster in 24 of 37 head-to-head benchmarks and within the measurement error in 11 more. These are its biggest leads over the fastest other library:
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).
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| What is measured | EasyEcs | Next fastest | vs EasyEcs |
|---|---|---|---|
| Save 10,000 entities and load them back | 146 μs | DefaultEcs 4.33 ms | 30× |
| Add a component to 100,000 entities by query, then remove it | 78.7 μs | Arch 1.21 ms | 15× |
| Spawn 10,000 entities beside 100,000, then destroy them | 138 μs | Friflo.Engine.ECS 380 μs | 2.75× |
| Query 100,000 players by value: a rating range, zone sums | 127 μs | Friflo.Engine.ECS 317 μs | 2.49× |
| Create 1,000 parent-child squads, destroy them in cascade | 452 μs | Friflo.Engine.ECS 1.06 ms | 2.35× |
| Count 100 inventories through an index (1 item traded) | 425 ns | DefaultEcs 838 ns | 1.97× |
| Add a status component to 5% of 100,000 entities, then remove it | 517 μs | Friflo.Engine.ECS 1.00 ms | 1.94× |
| Find the 10 of 100,000 entities written this tick | 507 ns | Arch 966 ns | 1.91× |
The full server tick is closer, because most of a tick is iteration over dense columns, bound by memory more than by the library:
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
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Time | vs EasyEcs | Allocated |
|---|---|---|---|
| EasyEcs 4.6 | 1.68 ms | 1.00× | 0 B |
| Friflo.Engine.ECS 3.6 | 1.83 ms | 1.08× | 0 B |
| Arch 2.1 | 5.76 ms | 3.4× | 535 KB |
| DefaultEcs 0.17 | 6.24 ms | 3.7× | 60.9 KB |
Every comparison, sorted by lead, with the ones where another library is faster and why: Comparison.
Creating entities in a fresh world
A server creates most of its entities in a world that has never held any: at start-up, or when it opens a map or a
match. ColdCreateComparison measures that moment: 100,000 entities of one, two or three components created in a new
world of each library, a new world for every call, three ways:
PerEntity: oneCreateEntityper entity, nothing reserved.PerEntity_Reserved: the same loop after reserving room for all of them:world.EnsureCapacity<T1, …, Tn>(n)in EasyEcs,EnsureCapacityon the store and the archetype in Friflo,EnsureCapacitywith the signature in Arch. DefaultEcs has no reservation per component set.Bulk: oneworld.CreateEntities(span, values)call. Only EasyEcs runs this case; the comparisons count each other library's fastest way against it.
Create 100,000 entities of one component in a fresh world
Without and with a reservation, and in one call. Shorter is faster.
- EasyEcs
- Friflo.Engine.ECS
- Arch
- DefaultEcs
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | PerEntity | 5.99 ms | 1.00× | 6.97 MB |
| Friflo.Engine.ECS | PerEntity | 15.3 ms | 2.56× | 7.99 MB |
| Arch | PerEntity | 3.76 ms | 0.63× | 4.00 MB |
| DefaultEcs | PerEntity | 13.1 ms | 2.19× | 11.1 MB |
| EasyEcs | PerEntity_Reserved | 1.94 ms | 1.00× | 2.67 MB |
| Friflo.Engine.ECS | PerEntity_Reserved | 11.3 ms | 5.8× | 3.29 MB |
| Arch | PerEntity_Reserved | 3.45 ms | 1.78× | 3.85 MB |
| EasyEcs | Bulk | 2.65 ms | 1.00× | 4.20 MB |
Pre-sized or in one call, EasyEcs is the fastest of the four. With three components, the reserved loop takes
2.60 ms and one CreateEntities call 2.71 ms; Arch, the next fastest,
takes 4.21 ms reserved, 1.62× as long.
One by one with nothing reserved, Arch is faster. EasyEcs takes 7.13 ms, 1.50× as long as Arch's 4.77 ms. Without a reservation, a fresh table grows by doubling, and so does the entity storage. Their arrays past 85,000 bytes go to the large object heap, and once the allocations there pass the runtime's budget, .NET starts a full collection: one per new world in this benchmark, and most of the difference. Arch keeps entities in chunks of 16 KB, small objects that never reach that heap. Friflo and DefaultEcs pay the collection too and stay slower than EasyEcs.
A reservation sizes the table and the entity storage once and puts the entity records on the pinned object heap, so the run stays under both budgets and no collection starts (D28); the loop without it takes 2.75× as long. So when you know how many entities a world is about to get, say so:
// The table of exactly these components, sized for the whole start-up
world.EnsureCapacity<Position, Velocity, Health>(100_000);
for (int i = 0; i < 100_000; i++)
world.CreateEntity(new Position(i, 0), new Velocity(1, 0), new Health(100));Entities that start with the same values can also come in one call, which sizes the table from the span and hands you the handles:
var garrison = new Entity[100_000];
world.CreateEntities(garrison, new Position(0, 0), new Velocity(0, 0), new Health(100));Only the first fill of a world pays the growth. A world that already has the room creates and destroys at full speed:
CreateDestroy in the single operations.
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Choosing an iteration API
Every API walks the same tables front to back. What differs is the bookkeeping around each row: a delegate call, an enumerator, a structural-change check. Pick the first row that fits:
| Need | Use | Measured |
|---|---|---|
| The per-entity logic of a system | a [ForEach] method | 0.91 ns per entity, against 1.28 ns for two plain arrays |
| Arithmetic over many rows | a batch [ForEach] method (spans), vectorized | 69.5 μs instead of 253 μs per-entity (100,000 entities) |
| Heavy per-entity work | [ForEach(Parallel = true)] | 884 μs instead of 1.68 ms (100,000 entities, 4 cores) |
| A loop outside systems, every tick | a static [ForEach] method run through its entry point, or a struct job (world.ForEach) | 33.7 μs, against 145 μs for a Query loop |
| A loop in a tool, a test or a request handler | foreach (var item in world.Query<...>()) | 30.5 μs, against 12.9 μs for a struct job (10,000 entities) |
| "How many?" / "Is there any?" | world.Count / world.Any | 1.20 μs for 100,000 rows whose bits must be tested |
| The few rows written since the last run | ITrackChanges + [Changed<T>] | 525 ns instead of 38.6 μs (10 of 100,000 written) |
| The entities that lost a component | ITrackChanges + [Removed<T>] | 830 ns (10 of 100,000 removed) |
| Entities by value | a value index | see IndexBenchmark below |
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
[ForEach] beats two plain arrays because its columns start on a 64-byte boundary: a row of a power-of-two-sized
component never straddles two cache lines. MicroBenchmarks.ForEachSystemWrite runs on a world with one table;
the other iteration rows of MicroBenchmarks use a world where every other entity also has Health (two tables), so
compare APIs within one world, not across them.
Regular code and the fastest code
The regular way is right for most systems: short, and already a generated struct job. When a system shows up in
WorldOptions.MeasureSystems timings (measuring systems), these rewrites are what the
benchmarks measure:
| Regular | Fastest | Measured |
|---|---|---|
A per-entity [ForEach] doing arithmetic with branches | A batch method vectorized with Vector<T>, branches as masks | 253 μs → 69.5 μs |
foreach (var item in world.Query<...>()) in a hot ad-hoc loop | A struct job with world.ForEach | 30.5 μs → 12.9 μs |
A bool flag tested in every row | A tag with [With<T>] / [Without<T>] | rows without the tag skipped 64 at a time; toggling flips a bit |
| Scanning every row for the few that changed | ITrackChanges + [Changed<T>] | 38.6 μs → 525 ns |
CreateEntity / Destroy in a loop | CreateEntities / DestroyEntities, Instantiate(prefab, span) | 334 μs → 157 μs |
| Setting a component on every entity one by one | world.SetAll / RemoveAll | 1.68 ms → 87.9 μs |
One method taking Maybe<T> | Two methods split by [With<T>] / [Without<T>] | 130 μs → 41.8 μs |
A QueryFilter built at the call | A static readonly filter | 74.8 ns → 21.6 ns per call |
| Heavy per-entity work on one thread | [ForEach(Parallel = true)] | 1.68 ms → 884 μs |
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Arithmetic over many rows: vectorize a batch method
The JIT does not vectorize this loop, and the bounce branches mispredict on many rows. The regular system:
public class BounceSystem : EcsSystem
{
[ForEach, Without<Dead>]
static void Move(ref Position p, ref Velocity v)
{
p = new Position(p.X + v.X, p.Y + v.Y);
if (p.X < 0 || p.X > 4096) v = v with { X = -v.X };
if (p.Y < 0 || p.Y > 4096) v = v with { Y = -v.Y };
}
}The fastest one takes spans (runs of consecutive rows; a table whose rows all match is one call), reads the
two-float components as one float span (X, Y, X, Y, ...) so every lane of a Vector<float> is one coordinate, and
turns the branches into a mask:
using System.Numerics;
using System.Runtime.InteropServices;
public class BounceSimdSystem : EcsSystem
{
[ForEach, Without<Dead>]
static void Move(Span<Position> positions, Span<Velocity> velocities)
{
var p = MemoryMarshal.Cast<Position, float>(positions);
var v = MemoryMarshal.Cast<Velocity, float>(velocities);
var max = new Vector<float>(4096f);
int i = 0;
for (; i <= p.Length - Vector<float>.Count; i += Vector<float>.Count)
{
var velocity = new Vector<float>(v[i..]);
var position = new Vector<float>(p[i..]) + velocity;
var outside = Vector.LessThan(position, Vector<float>.Zero) | Vector.GreaterThan(position, max);
position.CopyTo(p[i..]);
Vector.ConditionalSelect(outside, -velocity, velocity).CopyTo(v[i..]);
}
for (; i < p.Length; i++) // the rows left over
{
p[i] += v[i];
if (p[i] < 0 || p[i] > 4096) v[i] = -v[i];
}
}
}The cast is valid because the components hold only floats (no padding, no references), and unmanaged columns start
on a 64-byte boundary, so vector loads stay aligned. A batch method makes no structural change and reads entities
through an EntitySpan parameter only where it needs them. A scalar loop over spans gains little over the
per-entity method: write one to vectorize it.
Movement over 100,000 entities: per entity and vectorized
- EasyEcs
- Friflo.Engine.ECS
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | Iterate2 | 253 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | Iterate2 | 257 μs | 1.02× | 0 B |
| EasyEcs | Iterate2Simd | 69.5 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | Iterate2Simd | 80.7 μs | 1.16× | 0 B |
Ad-hoc loops: a struct job
world.Query is the convenient loop for tools and request handlers. For a loop that runs every tick outside a
system, write a struct job: world.ForEach specializes and inlines it per table. Mark it INoStructuralChanges and
declare its Writes (what a job declares).
public struct EnergyJob : IForEach<Velocity>, INoStructuralChanges // no structural change: the lean loop
{
public float Total; // a value field stays in a register during the pass and is copied back once
public static int Writes => 0; // reads only: no row counts as changed
public void Execute(ref Velocity v) => Total += v.X * v.X + v.Y * v.Y;
}var job = new EnergyJob();
world.ForEach<Velocity, EnergyJob>(ref job);
float energy = job.Total;Declare the job a ref struct when it must hold a ref or a Span (an output buffer, a caller's array).
ForEach, ForEachEntity and ForEachBatch accept ref struct jobs; the *Parallel calls do not, because each
thread gets its own copy of the job. For a total, a value field is faster than a ref field: a write through a
ref goes to memory on every row.
public ref struct CollectJob : IForEach<Position>, INoStructuralChanges
{
public Span<float> Xs; // the caller's buffer, at least as long as the matching rows
public int Count;
public static int Writes => 0;
public void Execute(ref Position p) => Xs[Count++] = p.X;
}A static [ForEach] method outside a system does the same with less code: the generator writes the job and an entry
point that takes the world (RunnerBenchmark measures both).
public static class Census
{
[ForEach, Without<Dead>]
static void CountWounded(in Health health, ref int wounded)
{
if (health.Value < 50) wounded++;
}
}int wounded = 0;
Census.CountWounded(world, ref wounded); // generated entry point: the job runs onceStates: tags, not flags
A flag costs a load and a branch in every row of every system that checks it. A tag is a filter: rows without it are skipped 64 at a time, and adding or removing it flips a presence bit while the entity keeps its row.
public record struct Unit(int Hp, bool Stunned) : IComponent; // regular: every system tests the flag
public class StunnedFlagSystem : EcsSystem
{
[ForEach]
static void Act(ref Unit unit)
{
if (unit.Stunned) return;
unit.Hp++;
}
}
public class StunnedTagSystem : EcsSystem // fastest: the filter does the test
{
[ForEach, Without<Stunned>]
static void Act(ref Health hp) => hp = hp with { Value = hp.Value + 1 };
}Toggling a status is where this shows against other archetype libraries: EasyEcs flips a bit, Friflo moves the entity to another archetype and back.
Stun 5% of 100,000 fighters, then recover them
- EasyEcs
- Friflo.Engine.ECS
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | Toggle | 517 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | Toggle | 1.00 ms | 1.94× | 0 B |
The few rows that changed: [Changed<T>]
A replication or persistence system that scans every row pays for the rows nobody wrote. Mark the component
ITrackChanges and filter with [Changed<T>]: unwritten tables, 4,096-row blocks and 64-row words are skipped.
Take the component by in, so the visit does not count as a write.
public record struct Shield(int Value) : IComponent, ITrackChanges;
public record struct ShieldReplica(int Value) : IComponent;
public class ShieldReplicationSystem : EcsSystem
{
[ForEach, Changed<Shield>]
static void Send(in Shield shield, ref ShieldReplica replica) => replica = new ShieldReplica(shield.Value);
}It pays when few rows are written, or when the written rows sit close together:
| Rows written of 100,000 | [Changed<T>] | Every row |
|---|---|---|
| 10 | 525 ns | 38.6 μs |
| 1,000, spread 97 rows apart | 38.9 μs | 67.2 μs |
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
When writes land in most 64-row words, nothing is skipped and testing the change ticks costs about what reading the
column does. For a cheap check over a column that most rows write every tick (a death check on Health), a plain
scan is as fast and simpler.
What went away: [Removed<T>]
Replicating a removal (a fire that went out) with a marker tag costs a structural change per removal and a pass over
the tags; comparing every row with what clients last received costs a scan. A tracked component's removal already
stamps its row, so [Removed<T>] visits only the entities that lost it, with the same skipping as [Changed<T>]:
public class ShieldLossSystem : EcsSystem
{
[ForEach, Removed<Shield>] // Shield : ITrackChanges (above)
static void Send(ref ShieldReplica replica) => replica = new ShieldReplica(0);
}Find the 10 of 100,000 entities that lost a buff
- EasyEcs
- Other libraries
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | Removed | 830 ns | 1.00× | 0 B |
| DefaultEcs | WhenRemoved | 39.6 μs | 48× | 0 B |
| Friflo.Engine.ECS | Event | 697 ns | 0.84× | 0 B |
| Arch | LostTag | 1.81 μs | 2.18× | 0 B |
The entity only where the row needs it
An Entity parameter builds a handle for every row, even when only a rare branch uses it, and it makes the system
run alone in a parallel stage. When the entities a system acts on can be told by a component, filter on it
([With<Dead>]) instead of testing every row. A batch method that needs the entity of a few rows takes an
EntitySpan, which builds a handle only for the rows it indexes.
A pass over 100,000 entities that rarely needs the entity
- EasyEcs
- Friflo.Engine.ECS
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | Entity | 49.0 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | Entity | 67.2 μs | 1.37× | 0 B |
| EasyEcs | EntityBatch | 38.5 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | EntityBatch | 37.0 μs | 0.96× | 0 B |
Waves of entities: bulk calls
private static readonly Prefab Goblin = new Prefab().SetPosition(0, 0).SetHealth(30);var wave = new Entity[1_000];
world.CreateEntities(wave, new Position(0, 0), new Velocity(1, 0)); // one pass through the structural gate
world.Instantiate(Goblin, wave); // a wave of a prefab, the same way
int removed = world.DestroyEntities<Dead>(); // every dead entity, one pass
int lifted = world.RemoveAll<Stunned>(); // every stun lifted, whole words of rowsA prefab built once (static readonly) costs one row copy per instance; the world finds
its target table once and caches it. entity.Set(a, b) and entity.Remove<A, B>() change several components in one
call: shorter to write, and the same cost as one call per component, since the second move takes a cached transition
(D29).
Do
The checklist for code that runs every tick. Find the system worth the effort first: WorldOptions.MeasureSystems
times every system run.
- Mutate through refs:
ref var hp = ref item.Component1;,ref var hp = ref entity.Get<Health>();. - Spawn with every component at once:
world.CreateEntity(a, b, c)places the entity in its final table;world.Instantiate(prefab)for a kind defined once.entity.Set(a, b)/entity.Remove<A, B>()change several components in one call: shorter, with the same cost as one call each. - Read with
in, write withref:inparameters,entity.Read<T>()or the generated property read;refparameters andentity.Get<T>()write. Arefaccess counts as a write of a tracked component, and aQueryloop counts every row it visits; a struct job that only reads declaresstatic int Writes => 0. - Keep
[ForEach]methods that make no structural changestatic, without aWorldparameter and with read-only use of theirEntity: the generator marks their jobINoStructuralChanges, which skips the per-row bookkeeping. Mark hand-written jobs the same way. - Take singletons as
[ForEach]parameters (resolved once per pass), or keep aSingletonRef<T>outside systems (no lookup per access). - Give systems a cadence:
UpdateInterval, or a system group updated when needed (Update<TGroup>()), instead of a counter checked in the method. - Keep components small (a few fields, well under 64 bytes) and split rarely used data into its own component: iteration loads only the columns it reads.
- Vectorize arithmetic in batch methods, use bulk calls for waves, tags for states,
[Changed<T>]for what changed and[Removed<T>]for what went away (above). - Ask
world.Count/world.Anyinstead of looping to count or to find one match. - Reserve room in a
DynamicBuffer<T>whose size is known (EnsureCapacity), and pre-size the world withWorldOptions.InitialEntityCapacityorworld.EnsureEntityCapacity(n), and a table before creating its entities one by one withworld.EnsureCapacity<T1, …, Tn>(n). - Keep
QueryFilters instatic readonlyfields (the generator does this for[ForEach]). - Look entities up with a value index (
IIndexed<TKey>) instead of a dictionary kept in sync by hand, and write an indexed component only when its key changes. - Run one world per thread on servers, for example one per map or zone.
Don't
- Don't modify a copy of a component and forget to write it back.
- Don't keep
refs acrossawaitor in fields: keep theEntityhandle. - Don't store raw entity indexes: ids are recycled; store an
EntityId(index and version). - Don't write lambdas that capture locals in methods that run every update: the closure is allocated at method
entry even when its branch is not taken.
AllocationTestscaught exactly this inWorld.Update(EECS028). - Don't use LINQ,
params object[]or string formatting in per-update code (EECS028). - Don't take an
Entityor a singleton parameter a method does not need: the loop loads it for every row (EECS026). - Don't take a tracked component by
refwhen the method only reads it: every visited row then counts as changed (EECS025). - Don't look up the visited entity's components or a singleton inside a
[ForEach]method: a parameter resolves them once per table (EECS027). - Don't make a
[ForEach]method an instance method when it uses nothing of its system: it then runs alone and pays the checks of a structural change (EECS029). - Don't use a value index, or destroy entities, from another thread: the index follows those changes on the owner thread and is not synchronized.
Pitfalls
| Mistake | What happens | Caught by |
|---|---|---|
| A batch method that also takes a per-entity parameter | It cannot receive runs of rows | EECS009 |
A structural change in a static [ForEach] method without Entity or World | The method promises no structural change, and its lean loop relies on it | EECS013 |
| A parallel method that writes a singleton or changes structure | Data races between the threads | EECS010 |
An Entity stored in a component | The column holds references: no longer pinned, scanned by the GC | EECS017 (warning) |
Writing an indexed component through a ref | The index cannot see the new key | EECS015 |
A computed UpdateInterval | Read every update | EECS018 (warning) |
A ref parameter that only reads a tracked component | Every visited row counts as changed | EECS025 (warning, code fix: in) |
| A closure or LINQ in per-update code | Garbage every tick | EECS028 (warning), and AllocationTests-style checks in your own tests |
A lookup through the visited Entity in a [ForEach] method | A search per row | EECS027 (warning) |
| A structural change entity by entity over a query | One row moved per call | EECS030 (warning, code fix: the bulk call) |
| Filling a fresh world one entity at a time, nothing reserved | Doubling arrays on the large object heap start a full collection (above) | EECS031 (warning, code fix: CreateEntities or EnsureCapacity<T1, …, Tn>(n)) |
What is covered
Every feature has unit tests (tests/EasyEcs.UnitTest), a BenchmarkDotNet benchmark and, where a peer library has
the feature, a head-to-head comparison that checks every library computes the same result before it measures.
| Feature | Tests | Benchmark | Against other libraries |
|---|---|---|---|
| A whole server tick | BattleServerTests | WorldSimulationBenchmark, MultiWorldBenchmark, BattleServerBenchmark | EcsComparisonBenchmark |
[ForEach], struct jobs, Query | ForEachSystemTests, QueryTests, RunnerTests | MicroBenchmarks, RunnerBenchmark, CallSiteBenchmark | OperationBenchmark |
| Structural changes, presence bits | EntityTests, ComponentTests, PresenceTests | MicroBenchmarks (Churn, ToggleComponent), SparseBenchmark, CountBenchmark | StructuralChangeComparison |
| Bulk changes and spawns | BulkTests | BulkBenchmark, MicroBenchmarks.ChurnBatch | BulkChangeComparison, BulkSpawnComparison |
| Prefabs and clones | InstantiateTests | PrefabBenchmark | OperationBenchmark (Instantiate) |
| Change tracking | ChangedTests | ChangeTrackingBenchmark | ChangeTrackingComparison |
| Removal detection | RemovedTests | BattleServerBenchmark | RemovalComparison |
| Disabling | DisableTests | BulkBenchmark (DisableAll) | DisableComparison |
| Value indexes, ordered indexes | IndexTests, OrderedIndexTests | IndexBenchmark, OrderedIndexBenchmark | IndexComparison, ValueQueryComparison |
| Relations | RelationTests, TargetPolicyTests | RelationBenchmark | RelationComparison |
| Hierarchy | HierarchyTests | HierarchyBenchmark | HierarchyComparison |
| Groups | GroupTests | GroupBenchmark | ValueQueryComparison |
| Singletons | SingletonTests | MicroBenchmarks.SingletonAccess | OperationBenchmark (Singleton) |
Optional components (Maybe<T>) | ForEachSystemTests | MaybeBenchmark | — |
| Dynamic buffers | DynamicBufferTests | DynamicBufferBenchmark | — |
| Cleanup components | CleanupTests | CleanupBenchmark | — |
| System ordering and groups | SystemTests | OrderingBenchmark | — |
Parallel systems and [ForEach(Parallel = true)] | ParallelTests, ConcurrencyTests | ParallelSystemsBenchmark, ParallelForEachBenchmark | ParallelSystemsComparison, ParallelQueryComparison |
| Snapshots | SnapshotTests | SnapshotBenchmark (Capture, Restore) | — |
| Saves | SerializationTests | SnapshotBenchmark (Save, Load) | SaveComparison |
| Moving entities between worlds | MoveTests | MigrationBenchmark | — |
| Unloading a plugin's types | UnloadTests | UnloadBenchmark | — |
| Introspection | IntrospectionTests | IntrospectionBenchmark | — |
| Generic systems | GenericTests | — | — |
| Generator, analyzer, code fixes | GeneratorTests, CodeFixTests | — | — |
| Zero allocation | AllocationTests (0 B budget on every test run) | the Allocated column of every benchmark | every comparison |
Benchmarks
Every class of benchmarks/EasyEcs.Benchmark, from one full run. Bars are EasyEcs; the ratio is against the class's
baseline, the first way of doing the job. The comparisons with other libraries are on
the comparison page.
Server ticks
WorldSimulationBenchmark and MultiWorldBenchmark are the headline world above. BattleServerBenchmark is one tick
of the battle server (BattleServer.cs), which uses every feature: a parallel [ForEach], two
systems that run at once, statuses added and removed mid-pass, WithAny, deaths, respawns and projectiles, a value
index, a relation, prefabs, an update interval, per-system timings and replication every third tick with
[Changed<T>] and [Removed<T>]. BattleServerTests checks the same world.
| Case | Entities | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| Tick | 10000 | 158 μs | — | 0 B |
| Tick | 100000 | 1.72 ms | — | 0 B |
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| TickAllWorlds | 924 μs | — | 0 B |
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Tick | 2.97 ms | — | 0 B |
Single operations
MicroBenchmarks isolate one operation each, over 10,000 entities. RawArrayWrite is the floor without an ECS: two
plain arrays. HandleAccess, TryGetEntity, TrackedHandleWrite, SingletonAccess and CountAndAny repeat their
call 1,000 times. CreateAddDestroy builds a fresh world each time, so its allocations are the new world and its
growth.
MicroBenchmarks: one operation each, 10,000 entities
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| CreateAddDestroy | 1.03 ms | 82× | 1.52 MB |
| Churn | 334 μs | 26× | 0 B |
| ChurnBatch | 157 μs | 12× | 0 B |
| RemoveMany | 51.0 μs | 4.0× | 0 B |
| ToggleComponent | 158 μs | 13× | 0 B |
| QueryIterate | 30.5 μs | 2.41× | 0 B |
| ForEachIterate | 12.9 μs | 1.02× | 0 B |
| QueryWrite | 18.9 μs | 1.49× | 0 B |
| RawArrayWrite | 12.8 μs | 1.01× | 0 B |
| ForEachSystemWrite | 9.13 μs | 0.72× | 0 B |
| ForEachWrite | 9.55 μs | 0.75× | 0 B |
| QueryIterate3 | 9.71 μs | 0.77× | 0 B |
| HandleAccess | 3.33 μs | 0.26× | 0 B |
| SingletonAccess | 1.01 μs | 0.08× | 0 B |
| TryGetEntity | 3.60 μs | 0.28× | 0 B |
| TrackedHandleWrite | 8.37 μs | 0.66× | 0 B |
| CountAndAny | 41.1 μs | 3.3× | 0 B |
CallSiteBenchmark measures a query call itself: a filter built at the call, a filter built once, no filter, and a
filter past the per-call memo (the query cache's dictionary). RunnerBenchmark runs one pass outside systems three
ways: a static [ForEach] method's entry point, the struct job it replaces written by hand, and a Query loop.
OrderingBenchmark shows that [UpdateAfter<T>] costs nothing per update: the order is resolved when systems are
added.
CallSiteBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| FilterAtCall | 74.8 ns | 1.00× | 0 B |
| FilterOnce | 21.6 ns | 0.29× | 0 B |
| NoFilter | 42.9 ns | 0.57× | 0 B |
| PastTheMemo | 88.0 ns | 1.18× | 0 B |
RunnerBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Runner | 33.7 μs | 1.00× | 0 B |
| HandWrittenJob | 56.7 μs | 1.69× | 0 B |
| Query | 145 μs | 4.3× | 0 B |
OrderingBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Registered | 20.9 μs | 1.01× | 0 B |
| Ordered | 20.8 μs | 1.01× | 0 B |
Presence bits and filters
SparseBenchmark keeps 10 burning units among 100,000 in one table (only their presence bits differ): a pass over the
few, a query over them, a count of them and a pass over the rest. CountBenchmark counts rows that must be tested one
by one (two columns with disabled rows), which is vectorized: 8 bit words per step with AVX-512. MaybeBenchmark
compares one method taking Maybe<Shield> with two methods split by [With<Shield>] / [Without<Shield>].
SparseBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| PassOverTheFew | 386 ns | — | 0 B |
| QueryTheFew | 365 ns | — | 0 B |
| CountTheFew | 13.6 ns | — | 0 B |
| PassOverTheRest | 52.3 μs | — | 0 B |
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Count | 1.20 μs | — | 0 B |
MaybeBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| OneMethod | 130 μs | 1.01× | 0 B |
| TwoMethods | 41.8 μs | 0.32× | 0 B |
Structural changes in bulk
BulkBenchmark stuns 100,000 fighters and lifts the stun, and disables a status for a zone and enables it, each in
bulk (SetAll / RemoveAll, DisableAll / EnableAll) and entity by entity. PrefabBenchmark spawns 1,000
entities from a prefab one by one and as a wave. CleanupBenchmark churns 1,000 of 10,000 sessions per operation with
a cleanup component against a plain component released by hand.
BulkBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| StunAndLift | 87.9 μs | 1.00× | 0 B |
| StunAndLiftEach | 1.68 ms | 19× | 0 B |
| DisableAndEnable | 22.9 μs | 0.26× | 0 B |
| DisableAndEnableEach | 2.27 ms | 26× | 0 B |
PrefabBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| InstantiateEach | 49.7 μs | 1.00× | 0 B |
| InstantiateBatch | 15.3 μs | 0.31× | 0 B |
CleanupBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Cleanup | 102 μs | 1.00× | 0 B |
| Plain | 43.9 μs | 0.43× | 0 B |
Change tracking
ChangeTrackingBenchmark replicates health: 10 (a quiet tick) or 1,000 of 100,000 entities are written per tick,
then one system copies health into a replica with [Changed<Health>] (Changed=True) or by visiting every row.
QueryTick does the same with an ad-hoc Query. DynamicBufferBenchmark replicates 1,000 changed bags of 100,000,
held as a DynamicBuffer<int> or as a List<int> in a tracked component.
ChangeTrackingBenchmark (Written=10)
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Changed | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| Tick | False | 38.6 μs | — | 0 B |
| QueryTick | False | 476 μs | — | 0 B |
| Tick | True | 525 ns | — | 0 B |
| QueryTick | True | 720 ns | — | 0 B |
DynamicBufferBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | List | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| Tick | False | 56.5 μs | — | 0 B |
| Tick | True | 61.8 μs | — | 0 B |
The "every row" cases vary from run to run on the reference VM (they depend on how 100,000 rows land in physical
memory); the [Changed] cases are stable.
Indexes, relations, groups and hierarchies
IndexBenchmark uses a relation as an inventory: 100,000 items point at one of 1,000 owners; 100 trades, then 100
inventories counted. OrderedIndexBenchmark keeps a leaderboard of 100,000 scores (1,000 change, then the top 10 and
one bracket read) against a scan. GroupBenchmark sums the players of 4 of 16 zones as a group (a table per zone), a
value index and a scan. RelationBenchmark rewires 100 of 10,000 friend lists and walks 100 follower sets.
HierarchyBenchmark destroys 1,000 squad leaders with their members (ChildOf, cascade) against links that are only
removed.
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| TradeAndCount | 5.28 μs | — | 0 B |
OrderedIndexBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Ordered | 75.8 μs | 1.00× | 0 B |
| Scan | 307 μs | 4.1× | 0 B |
GroupBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Group | 47.4 μs | 1.01× | 0 B |
| Index | 138 μs | 2.93× | 0 B |
| Scan | 742 μs | 16× | 0 B |
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| FollowAndCount | 22.7 μs | — | 0 B |
HierarchyBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Cascade | 590 μs | 1.00× | 0 B |
| RemoveLinks | 516 μs | 0.88× | 0 B |
Threads
ParallelSystemsBenchmark runs four [ForEach] systems with disjoint access over 100,000 entities, with
WorldOptions.ParallelSystems off and on: on, they form one stage and run at once. ParallelForEachBenchmark runs one
heavy method (steering towards the nearest of 16 waypoints) plain and with Parallel = true, and the same work as an
ad-hoc job with entity handles (ForEachEntity / ForEachEntityParallel).
ParallelSystemsBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Parallel | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| Tick | False | 420 μs | — | 0 B |
| Tick | True | 295 μs | — | 0 B |
ParallelForEachBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Parallel | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| Tick | False | 1.68 ms | — | 0 B |
| EntityJob | False | 1.92 ms | — | 0 B |
| Tick | True | 884 μs | — | 0 B |
| EntityJob | True | 896 μs | — | 0 B |
The reference machine has 4 cores and the parallel rows carry a large error in this run: read them as "faster on several cores", not as a precise speed-up.
Snapshots, saves, migration and unloading
SnapshotBenchmark captures a world of 100,000 entities (two tables, a third of the ids recycled, a singleton) into a
new snapshot, restores one in place, saves it as bytes into a reused buffer and loads it back. Capture allocates
the snapshot it returns; capture into an existing snapshot to reuse it. MigrationBenchmark moves 10 players with 99
items each to another world and back, through bytes (SaveEntities / LoadEntities) and in memory
(MoveEntities); SaveAndLoadOne is the fixed cost of a save. UnloadBenchmark removes a plugin's types from a world
of 10,000 or 100,000 players (RemoveTypes), the step before reloading game logic.
SnapshotBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Capture | 931 μs | — | 2.67 MB |
| Restore | 428 μs | — | 0 B |
| Save | 262 μs | — | 0 B |
| Load | 1.00 ms | — | 0 B |
MigrationBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| SaveAndLoad | 222 μs | 1.00× | 0 B |
| Move | 165 μs | 0.74× | 0 B |
| SaveAndLoadOne | 2.22 μs | 0.01× | 0 B |
| SaveRecord | 104 ns | 0.00× | 0 B |
| LoadRecord | 722 ns | 0.00× | 0 B |
UnloadBenchmark
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Case | Players | Mean | vs baseline | Allocated |
|---|---|---|---|---|
| RemoveTypes | 10000 | 247 μs | — | 2.95 KB |
| RemoveTypes | 100000 | 2.38 ms | — | 2.95 KB |
Introspection
IntrospectionBenchmark describes the battle server's world for a dashboard (world.Describe(): every table with
its columns, rows and bytes) and one entity for a debugger (entity.Describe(), values boxed). Both allocate the
description they return: they are tools, not tick paths.
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Tables | 10.6 μs | — | 25.0 KB |
| Entity | 244 ns | — | 832 B |
How to reproduce
Numbers come from BenchmarkDotNet only, never from a stopwatch:
dotnet run -c Release --project benchmarks/EasyEcs.Benchmark -- --filter '*' # every class on this page
dotnet run -c Release --project benchmarks/EasyEcs.Benchmark -- --filter '*World*' # the headline ticks
dotnet run -c Release --project benchmarks/EasyEcs.Comparison -- --filter '*' # other libraries
dotnet run -c Release --project benchmarks/EasyEcs.Comparison -- --check # correctness of the ports onlyBoth projects use the job in benchmarks/EasyEcs.Benchmark/BenchmarkConfig.cs: 2 launches, 6 warmups, 8 iterations
of 250 ms, and call counting from the start (DOTNET_TC_CallCountingDelayMs=0) so the warmups reach optimized code.
Two processes are measured instead of many iterations of one, because run-to-run differences (code layout, tiering)
are larger than the noise within a run. The machine of the numbers on this site:
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
AllocationTests guard the zero-allocation contract on every test run (dotnet test): the steady-state tick, queries,
structural changes, indexes, relations, cascades and parallel passes must allocate 0 bytes after warm-up.
Related
Why EasyEcs is fast
The storage, generated jobs and caches behind these numbers.
Comparison with other ECS libraries
The same work in Friflo.Engine.ECS, Arch and DefaultEcs, with every result.
Queries and filters
Query, struct jobs, Count and Any, and what a job declares.
Systems and [ForEach]
Batch methods, parallel methods, groups, intervals and timings.
Last updated on
How is this guide?
Glossary
Every Entity Component System term the EasyEcs docs use, from entity and archetype to change tick, structural gate and collectible AssemblyLoadContext.
Why EasyEcs is fast
The mechanisms behind EasyEcs' speed, each tied to a benchmark: aligned archetype columns, 16-byte entity records, presence bits, generated jobs and SIMD.