Skip to content

KenseiECS Performance Benchmarks ​

All numbers below come from one machine: .NET 8.0.14, Windows 11, x64 RyuJIT AVX2, BenchmarkDotNet 0.14.0. LeoECS, LeoEcsLite, Arch, the memory footprint and the 2.0-versus-1.0 table come from September 2026, default job. The KenseiECS numbers are for 2.4.0: the September 2.0 numbers scaled by how much 2.4.0 differs from 2.0.0, measured in October 2026 with both versions in the same session (median of four interleaved runs), so they stay comparable with the other frameworks. Sources live in Benchmark/; run them with:

dotnet run -c Release --project Benchmark -- --filter '*'

Contestants:

  • KenseiECS — sparse set ECS with reactive filters and owning groups
  • LeoEcsLite (Leopotam.EcsLite 1.0.1) — sparse set ECS, widely used in Unity
  • LeoECS (Leopotam.Ecs 1.0.1) — legacy version, kept for reference
  • Arch (2.1.0) — archetype ECS

All frameworks allocate nothing at runtime in every scenario except entity creation (which grows arrays).

What these numbers do not cover:

  • Runtime. Only .NET 8 x64 RyuJIT was measured. Unity's Mono and IL2CPP backends and ARM devices (Android, iOS) were not, and the numbers do not transfer to them as-is. The benchmarks also run the net8.0 build of KenseiECS, which uses .NET-only intrinsics where the netstandard2.1 build that Unity compiles falls back to portable code (for example, BitOperations.TrailingZeroCount versus a portable shift-and-mask count when walking component masks).
  • Scenarios. None uses EventBuffer<T>, world.AddEvent or OneFrame<T>/DelHere<T> cleanup.
  • Allocations. "0 B" is measured after [GlobalSetup] and BenchmarkDotNet's warm-up iterations, when pools, filters and buffers already have the capacity the benchmark needs. A real game allocates whenever a pool, filter, entity table, CommandBuffer or pooled EventBuffer<T> list grows past its previous peak; zero allocations hold only after every capacity has reached its peak. Set capacities up front with WorldConfig to shorten that phase. World.Warmup does not grow capacities to that peak, and it does not fill the EventBuffer<T> list pool.

Iteration — component traversal ​

foreach over Position + Velocity, read and write, 10,000 entities created in order.

Framework10,000 entities
KenseiECS, filter13.8 us
KenseiECS, owning group5.5 us
LeoECS12.8 us
LeoEcsLite14.0 us
Arch5.4 us

A filter loop pays two sparse lookups per entity (dense -> sparse -> data for each component) and lands next to LeoEcsLite. An owning group keeps the two pools' dense arrays aligned, so the loop reads Data1[i] and Data2[i] with no lookup at all and matches Arch's archetype iteration.


Fragmented iteration — after a long session ​

Same loop, but the world was built by creating 20,000 entities, adding Velocity in shuffled order and destroying half in shuffled order. Filter order, pool order and entity indices no longer line up, which is what a real game looks like after minutes of play.

Framework10,000 entities
KenseiECS, filter14.8 us
KenseiECS, owning group5.5 us
LeoEcsLite16.7 us
Arch5.4 us

Sparse-set filters lose ~7% (KenseiECS) to ~20% (LeoEcsLite) to cache misses; groups are unaffected because their data stays contiguous whatever the history.


Create Entity — spawning entities with components ​

Creating N entities with Position + Velocity into a fresh world (includes growing every array).

Framework10,000 entitiesAllocated
KenseiECS292 us1.60 MB
LeoECS380 us2.31 MB
LeoEcsLite344 us1.86 MB
Arch208 us0.58 MB

Arch allocates whole archetype chunks; sparse-set frameworks grow one array per pool. KenseiECS stays ahead of both Leo variants.


Structural changes — adding and removing components ​

Add Health to all N entities, then remove it from all. No filter watches Health in this scenario.

Framework10,000 entities
KenseiECS87 us
LeoECS145 us
LeoEcsLite73 us
Arch590 us

LeoEcsLite keeps no per-entity bitmask, so with nothing observing the type it does strictly less work. KenseiECS pays for the mask update and the component count on every change; that bookkeeping is what makes the next two scenarios cheap. Arch migrates the entity between archetypes on every change.


Observed structural changes — filters watching the changed type ​

Same add + remove, but F filters constrain Health: half of them Inc<Position, Health, Extra>, half Inc<Position> Exc<Health, Extra>, each with a distinct extra type so none deduplicate.

Filters watching HealthKenseiECSLeoEcsLite
1135 us204 us
8319 us909 us
321,008 us4,356 us

KenseiECS tests one mask word per filter (and skips the test entirely for the half of the filters a change cannot move the entity into); LeoEcsLite walks a Has chain per included type for every filter. With 32 filters on the type KenseiECS is 4x faster, and real projects have far more than 32 filters over their hottest components.


Wide masks — 1,024 registered component types ​

The production shape: 1,024 component types registered, the benchmarked types placed past the 16th mask word, every entity carrying a 17-word mask, three filters spanning two words watching Health.

Scenario, 10,000 entitiesKenseiECSLeoEcsLite
Iteration (2 comp, Exc on a third)13.6 us14.3 us
Structural (add + remove Health, 3 filters)235 us341 us
Destroy all + create all (2 comp)561 us732 us

Mask width does not touch iteration, and a change on a high-index type costs the same as on a low one: matching reads only the words a filter constrains. Destroying an entity reads word 0 and the mask words that may hold its components (two of the 17 words here) instead of every pool, which keeps destroy + create ahead of LeoEcsLite's mask-free design.


Memory footprint ​

Bytes held by a world after N entities were created and each of T component types was added to at least one high-index entity (every pool's sparse array grows to the highest entity index that ever had the component), plus F filters.

TypesFilters10,000 entities
6403.7 MB
641004.1 MB
1,024044.3 MB
1,02410044.9 MB

The cost model is O(types x entity capacity): ~40 KB per pool at 10,000 entities, dominated by the sparse array. Filters are paged (a page covers 1,024 entity slots and is allocated on first touch), so 100 filters add well under a megabyte.


Game loop — a realistic frame ​

Movement over Position + Velocity, health regeneration over Health, add a one-frame Damage to 10% of entities, run the damage system, remove Damage.

Framework10,000 entities
KenseiECS35 us
LeoEcsLite40 us
Arch78 us

Per frame at 60 FPS this is 0.2% of the budget. Iteration dominates and structural changes are a minority, which is where the sparse-set + reactive-filter design pays off against archetype migration.


Summary ​

Operationvs LeoEcsLitevs Arch
Iteration, filteron par2.5x slower
Iteration, owning group2.5x fasteron par
Fragmented iteration, group3x fasteron par
Entity creation1.2x faster1.4x slower
Structural changes, unobserved type1.2x slower6.8x faster
Structural changes, 32 filters observing4.3x faster—
1,024 types: structural1.5x faster—
1,024 types: destroy + create1.3x faster—
Game loop1.1x faster2.2x faster
Runtime allocations, after capacities reach their peak0 B0 B

2.0 versus the 1.0 core ​

Same machine, same session, the 1.0 core (commit 903dbf2) built against the same benchmark sources. 10,000 entities.

Scenario1.0 core2.0Change
Iteration, filter13.9 us13.9 ussame
Iteration, owning group—5.5 usnew, 2.5x faster than the filter
Fragmented iteration, filter15.9 us14.9 us6% faster
Entity creation300 us294 us2% faster
Structural, unobserved type105 us100-105 uswithin noise
Structural, 8 filters observing381 us334 us12% faster
Structural, 32 filters observing1,146 us1,083 us5% faster
1,024 types: structural, 3 filters234 us243 us4% slower
1,024 types: destroy + create700 us645 us8% faster
Game loop32 us33 us4% slower
100 filters, memory (64 types)2.6 MB0.36 MB7x less
100 filters, memory (1,024 types)4.0 MB0.56 MB7x less

The two small regressions are the price of paged filter sparse arrays (one more indirection when an entity enters or leaves a filter) and of the hook infrastructure behind listeners, groups and change tracking (one predictable branch per add and remove). Everything that iterates is unchanged or faster; everything that changes structure under observation is faster; filters cost a fraction of the memory.

Where the numbers come from ​

  • Sparse sets — O(1) add, remove and has.
  • Owning groups — pools kept aligned so hot loops read arrays directly.
  • Reactive filters with per-type include/exclude/any lists — a change only tests the filters it can move the entity into, one mask word each.
  • Multi-word bitmasks — unlimited component types; destroy and copy walk the mask, not the pools.
  • Paged filter sparse arrays — filters cost memory proportional to the entities they touch.
  • Struct enumerator with a sentinel terminator — one bounds check per step, no allocations.

Comparing versions ​

BenchmarkCompare/ runs the benchmarks of Benchmark/ against several versions of KenseiECS and writes one table per benchmark class, the versions side by side with the change against the first one and the allocations. Each version is a git ref (a tag such as v2.2.1) or wt, the working tree; every ref is checked out into a temporary git worktree with today's Benchmark/ sources, so all versions run the same benchmark code and only the KenseiECS sources differ.

dotnet run -c Release --project BenchmarkCompare -- --versions v2.0.0,v2.2.1,v2.2.2,wt --filter "*KenseiECS*"
  • --filter takes BenchmarkDotNet's filter (*KenseiECS* runs the KenseiECS methods of every class; *GameLoopBenchmark* one class with all frameworks).
  • --job short (or dry, which only checks that everything runs) shortens a run; without it the default job runs, as for the tables above.
  • --out <dir> sets where the results go (default BenchmarkDotNet.Artifacts/compare-<date>/): the BenchmarkDotNet artifacts per version and comparison.md.

The versions run one after another, so run the comparison on an idle machine: a background load that changes between two versions shows up as a difference between them.