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.
EasyEcs is fast because a server tick does the least work the data allows: it walks dense, aligned columns, skips 64
rows with one bit test, calls your code without a delegate, changes structure without a command buffer and
allocates nothing. None of this needs you to write unusual code: a plain [ForEach] method gets all of it. Each
section below names one mechanism, where it lives in the source and the benchmark that measures it.
A [ForEach] write, per entity
0.91ns[Changed<T>] over a full scan
73×Allocated per server tick
0BThe short answer
| Mechanism | What it saves | Measured |
|---|---|---|
| Archetype tables, 64-byte-aligned columns | Pointer chasing and split cache lines | 0.91 ns per entity, below two plain arrays (1.28 ns) |
| 16-byte entity records | A second lookup per handle access | MicroBenchmarks.HandleAccess |
| Presence bits | A row copy per state change | 517 μs against 1.00 ms for Friflo, which moves rows |
| Generated struct jobs | A delegate call per row | 33.7 μs against 145 μs for a Query loop |
| Lock-free query cache | Locks and table searches per call | 21.6 ns per query call |
| Change-tick summaries | Visiting rows nobody wrote | 525 ns against 38.6 μs for a scan |
| Immediate structural changes | Recording and replaying a command buffer | StructuralChangeComparison |
| Zero allocation | GC pauses | 0 B per tick |
| SIMD | One instruction per row or per word | 1.20 μs to count 100,000 rows bit by bit |
| The parallel runner | Waking threads that do not pay | 884 μs against 1.68 ms |
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Archetype tables with aligned columns
Entities with the same set of components share a table (an archetype): one column per component type, one row per entity, structure of arrays. A system walks the columns it needs front to back, which is the access pattern hardware prefetchers and vector units handle best.
- Unmanaged columns are pinned and aligned. A column of a type without references is a byte array on the pinned
object heap whose row 0 starts on the first 64-byte boundary (
Archetype.Aligned). A row of a power-of-two-sized component never straddles two cache lines, vector loads stay aligned, and the GC never scans or moves the column. - Columns are contiguous, not pages: a handle access is one indexed load. Paging would only save the copy when a
table grows, which
InitialEntityCapacityremoves (D7). - Each row's entity is one 8-byte
EntityId(version and index side by side), so a handle is built with one load. - Moves follow cached edges. Gaining a component the table has no column for copies the row to the target table along a transition cached per component bit (and per generic signature for several components), with a copy plan computed once per edge.
The aligned columns are why the generated job beats the same loop over two plain arrays:
Add Velocity to Position for 10,000 entities
RawArrayWrite is two plain arrays, the floor without an ECS. ForEachSystemWrite is a [ForEach] system, ForEachWrite a hand-written struct job.
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 |
|---|---|---|---|
| RawArrayWrite | 12.8 μs | 1.01× | 0 B |
| ForEachSystemWrite | 9.13 μs | 0.72× | 0 B |
| ForEachWrite | 9.55 μs | 0.75× | 0 B |
16-byte entity records
Everything the world keeps per entity id is one EntityMeta: its table, its version and its row, 16 bytes, so four
fit in a 64-byte cache line (EntityMeta.cs). The component set is the table's mask, not a per-entity copy.
entity.Get<T>() is a version check on that record, a column lookup in the table (bit to column, one small array
whose 16-byte entries hold the column and its presence bits) and one indexed load.
- Ids are recycled last in, first out: a freed id's cache lines are still warm when it comes back, and the records stay bounded by the peak number of live entities.
- The records never shrink, which lets handles index them without bounds checks.
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| HandleAccess | 3.33 μs | 0.26× | 0 B |
| TryGetEntity | 3.60 μs | 0.28× | 0 B |
| TrackedHandleWrite | 8.37 μs | 0.66× | 0 B |
| SingletonAccess | 1.01 μs | 0.08× | 0 B |
Each row repeats its call 1,000 times.
Presence bits
Removing a component does not move the entity. The row keeps its place and clears one bit in the column's presence
bits (64 rows per ulong); adding the component back sets the bit again (D6). Only gaining a
component the table has no column for moves the row, so a state that comes and goes (stunned, burning, dead) costs a
bit flip after the first time.
yes
no, first time
Remove<Stunned>()
clear the row's bit
the entity keeps its row
Set(new Stunned())
table has a
Stunned column?
set the row's bit
copy the row to
the table with one
Queries read the bits too. Each column counts its rows lacking the component, so per table a pass knows whether to skip it, walk every row with no test, or test bits, 64 rows per load. A rare state in a large table costs a pass over the words where it is set:
10 burning units among 100,000 in one table
Only presence bits tell them apart. The pass over the few skips the words without a burning row; the pass over the rest spans whole words.
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 |
Archetype libraries without presence bits move the entity to another table 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 |
Generated struct jobs instead of delegates
A [ForEach] method is compiled into a struct job by the source generator, and the world runs it through a generic
method constrained to that struct: world.ForEach<Position, Velocity, MoveJob>(ref job, in filter). The JIT
specializes the row loop for each job type and inlines your method into it. There is no delegate, no virtual call
per row and no closure.
[ForEach] static void Move(ref Position p, in Velocity v)
generator
struct MoveJob : IForEach<Position, Velocity>
+ INoStructuralChanges
static readonly QueryFilter
access: writes Position, reads Velocity
world.ForEach<Position, Velocity, MoveJob>
specialized and inlined by the JIT
What the generator also decides for you:
INoStructuralChangeswhen the method is static, takes noWorldand uses itsEntityonly to read: the pass then skips the bookkeeping that keeps structural changes safe. A method that does change structure gets the safe loop.Writes, from therefparameters, so a structural change mid-pass carries exactly those writes to the entity's new row, and tracked components count as written only throughref.- The system's access (reads and writes per component and singleton), which decides which systems may share a parallel stage.
- The filter as a
static readonlyfield, built once.
The generated code reaches private methods through UnsafeAccessor, so systems need no partial and the call
compiles to a direct call. A static [ForEach] method outside a system gets an entry point that takes the world:
it runs as fast as the struct job it replaces, written by hand.
Count the wounded of 100,000 fighters outside a system
Runner: a static [ForEach] method's generated entry point. HandWrittenJob: the struct job it replaces. Query: a foreach loop.
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 |
Lock-free query cache snapshots
A query call does not search tables. The world keeps a cache keyed by the query's components and filter sets
(required, excluded, any, changed, removed); each entry is an immutable snapshot of the matching tables and one row
filter per table. When a new table appears, every matching entry is replaced copy-on-write and published with
Volatile.Write, so readers never lock and never see a list being changed. In front of the cache, each call
signature keeps a small memo of its first four filters, and a QueryFilter holds no object reference, so building
one is a plain struct copy (D18).
hit
miss
copy-on-write,
Volatile.Write
world.Count<Npc>(filter)
memo of this
signature
entry: tables + row filters
cache dictionary
new table
The cost of a query call: counting a few entities
FilterAtCall builds the filter at the call; FilterOnce keeps it in a static field; NoFilter passes none; PastTheMemo uses a fifth filter, past the memo.
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 |
Change-tick summaries per word and per block
A component marked ITrackChanges gets a hidden column of 8-byte ticks: each row's tick of its last write. On top
of it the table keeps summaries (D23):
older than the pass
older
rest older
mixed
column: latest tick
skip the table
block of 4,096 rows:
latest tick + written words
skip the block
word of 64 rows: 32-byte summary
latest tick, its rows, bound of the rest
take the written rows from the summary
compare the row ticks, 4 per SIMD instruction
A [Changed<T>] pass skips a table nobody wrote with one load, then unwritten blocks, then unwritten words (four
summaries per SIMD compare), and finds the next written word of a block with one bit scan. Removing a tracked
component stamps the row's tick while the row clears its presence bit, so [Removed<T>] needs no extra storage, and
its own block summaries keep writes of T from making it visit their words. Components without ITrackChanges have
no column and no stamping code: the checks are JIT-time constants.
Replicate the 10 of 100,000 entities written since the last run
Changed=True: a [Changed<Health>] system or a Changed filter. Changed=False: visiting every row. Tick is a system, QueryTick an ad-hoc Query.
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 |
Immediate structural changes
Adding, removing, creating and destroying apply at once, also in the middle of a pass over the same table (D2). Other libraries record such changes in a command buffer and replay them later, which costs a record per change and a second walk. EasyEcs pays only inside passes:
- While a pass runs, a row that loses its entity becomes a tombstone (a negative id) instead of being filled, so rows never shift under the pass. The last pass to end closes the tombstones with vectorized scans.
- A pass records each table's row count before it walks, so entities created or moved in during the pass are not visited: each entity is visited at most once.
- Every change that can reallocate storage, move rows or flip presence bits bumps
StorageVersion. The row loop checks it after each entity and re-reads its column refs only when it changed. Tables without tombstones run a row loop compiled without the tombstone check (D25).
Mark the dead and revive them during two passes over 100,000 units
- 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 | Direct | 78.2 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | CommandBuffer | 75.4 μs | 0.96× | 0 B |
| Arch | CommandBuffer | 184 μs | 2.36× | 5.30 KB |
| DefaultEcs | CommandRecorder | 496 μs | 6.3× | 0 B |
Zero allocation
A busy world allocates nothing per tick, so a long-running server has no GC pauses from the ECS. The rule is enforced,
not hoped for: AllocationTests run a frame of updates, queries, structural changes, tracked removals, index churn,
prefab waves, relations, cascades and parallel passes 100 times after warm-up and require
GC.GetAllocatedBytesForCurrentThread() to be unchanged, on every dotnet test.
What makes it hold:
- Struct jobs and struct enumerators: no delegate, no closure, no boxing on any iteration path.
- Pooled cold state: a
Querywalk's per-table bookkeeping lives in aQueryWalkpooled per thread and nesting level. - Caches built once: transition edges, query entries, prefab target tables and overflow masks are allocated when first needed, never on the steady path.
- Bounded growth: tables double when full and never shrink, ids are recycled, buffers are reused.
- The parallel runner uses reusable thread-pool work items, not
Parallel.For(a closure and state per call).
The same tick in other libraries, with what each allocates per tick:
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 |
AllocationTests once caught a lambda that captured locals in World.Update: the closure was allocated at method
entry even when its branch was not taken. That is the kind of regression the test exists for.
SIMD
Vector instructions appear where they measure (D21):
| Where | What is vectorized |
|---|---|
| Table matching | Component masks are 256-bit Vector256 bitsets: one test per table for the first 256 component types |
Count / Any on tables whose rows must be tested | The set bits of the row words, 8 words per step with AVX-512 (Vector512), else Vector<T> |
| Change filters | Word summaries 4 per compare; row ticks of mixed words 4 per instruction |
| Writes of a run of rows | One vectorized fill of their ticks |
| Closing tombstones | Rows read as longs and searched for negative ids |
| Your systems | Batch [ForEach] methods take spans of aligned columns, ready for Vector<T> |
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| Count | 1.20 μs | — | 0 B |
Movement over 100,000 entities: per entity and as a vectorized batch method
- 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 |
The parallel runner
Parallel work runs on the calling thread plus up to MaxDegreeOfParallelism - 1 reusable IThreadPoolWorkItem
helpers (D22). Two kinds of work use it:
- Parallel stages: with
WorldOptions.ParallelSystems, consecutive systems with no order between them and no conflicting access (from the generated access sets) form one stage and run at once. [ForEach(Parallel = true)]: a method's rows run in chunks, a multiple of 64 rows (so presence-bit words never straddle chunks), about four per thread, between 1,024 and 16,384 rows.
yes
no
probe after 16..1,024 runs,
or when 1.5x slower
a fifth faster than the work
Update
helpers paid off
last runs?
caller + pool work items
take chunks
caller runs alone
Each job and each stage measures its own runs: helpers stay while they make a run at least a fifth faster than its work, and a job that runs alone probes again after a period that doubles from 16 to 1,024 runs. Waking a parked pool thread costs from a few to a few hundred microseconds, so a small pass between ticks runs alone instead of burning CPU. There is no spinning and no dedicated thread.
Steering 100,000 entities, one thread and parallel
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 |
Four independent systems, sequential and as one parallel stage
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 |
The reference machine has 4 cores, and the parallel rows of this run carry a large error: read them as "faster on several cores", not as a precise speed-up.
What it costs
The same choices have prices, and they are deliberate:
- Gaining a new component copies the row to another table. The first time a state appears on an entity it moves; after that it flips a bit.
- Tables never shrink. Memory is bounded by the peak number of entities each table held.
- One owner thread per world. Structural changes and component writes belong to it (D13); parallelism comes from parallel stages, parallel methods and one world per thread.
- .NET 10 only (D15): no Unity, no older runtimes.
Related
Last updated on
How is this guide?
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.
Architecture
How EasyEcs stores entities and components, keeps tables dense under churn, caches queries, schedules systems and generates code, and what must always hold.