Home

Awesome

fennecs logo fennecs logo

... the tiny, tiny, high-energy Entity-Component System!

dotnet add package fennecs
to use the beta versions, append --prerelease

<table style="width: 100%"> <tr> </tr> <tr> <td> <img src="https://fennecs.tech/logos/fennecs.png" alt="a box of fennecs, 8-color pixel art" style="min-width: 320px; max-width: 320px"/> </td> <td style="width: fit-content"> <h1>Okay, what the fox!<br/><em>Another ECS?!</em></h1> <p>We know... oh, <em>we know.</em> 😩</p> <p>But in a nutshell, <a href="https://fennecs.tech"><b>fenn</b>ecs</a> is...</p> <p> 🐾 zero codegen<br/> 🐾 minimal boilerplate<br/> 🐾 archetype-based<br/> 🐾 intuitively relational<br/> 🐾 lithe and fast<br/> </p> </td> </tr> <tr> <th colspan="2"> <a href="https://discord.gg/3SF4gWhANS"><img alt="Discord" src="https://img.shields.io/badge/discord-_%E2%A4%9Coutfox%E2%A4%8F-blue?logo=discord&logoColor=f5f5f5"/></a> <a href="https://www.nuget.org/packages/fennecs/"><img alt="Nuget" src="https://img.shields.io/nuget/v/fennecs?color=blue"/></a> <a href="https://www.nuget.org/packages/fennecs/"><img alt="Downloads" src="https://img.shields.io/nuget/dt/fennecs"/></a> <a href="https://github.com/outfox/fennecs/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/outfox/fennecs/xUnit.yml"/></a> <a href="https://github.com/outfox/fennecs/issues?q=is%3Aissue+is%3Aopen+label%3Abug"><img alt="Open Bugs" src="https://img.shields.io/github/issues-search/outfox/fennecs?label=bugs&color=green&query=is:open label:bug"/></a> </th> </tr> </table>

Quickstart

Brand new? Try the cookbook for a quick & tasty intro, or dive into the docs!</br> Familiar with ECS architectures? Get an overview of new & unique concepts!

At the basic level, all you need is a 🧩component type, a number of small foxes 🦊entities, and a query to βš™οΈiterate and modify components, occasionally passing in some uniform πŸ’Ύdata.

// Declare a component record. (we can also use most existing value & reference types)
record struct Velocity(Vector3 Value);

// Create a world. (fyi, World implements IDisposable)
var world = new fennecs.World();

// Spawn an entity into the world with a choice of components. (or add/remove them later)
var entity = world.Spawn().Add<Velocity>();

// Queries are cached & we use ultra-lightweight Stream Views to feed data to our code!
var stream = world.Query<Velocity>().Stream();

// Run code on all entities in the query. (exchange 'For' with 'Job' for parallel processing)
stream.For(
    uniform: DeltaTime * 9.81f * Vector3.UnitZ,
    action: (Vector3 uniform, ref Velocity velocity) =>
    {
        velocity.Value -= uniform;
    }
);

πŸ’’... when we said minimal boilerplate, <em>we meant it.</em>

By any measure, we're talking just a couple of lines to get this gravity feature up and running. Creating the world and query is the only setup – the real slam dunk is how cleanly we built the full actor/gravity logic with barely any ceremonial code in sight.

And there's more: all that simplicity doesn't force any performance trade-offs! You get to have your cake and eat it too with zero confusion or fluff!


πŸ’‘Highlights / Design Goals


πŸ“• DOCUMENTATION: fennecs.tech (official website)

Grab a cup of coffee to get started, try the Cookbook, view the Demos , and more!
coffee cup


⏩ Nimble: fennecs benchmarks

Preliminary (WIP) benchmarks suggest you can expect to process over 2 million components per millisecond on a 2020 CPU without even customizing your logic.

Using Doraku's synthetic Ecs.CSharp.Benchmark, fennecs scores among the faster ECS in the benchmark suite.
(link goes to PR #36 to reproduce)

[!WARNING] These are synthetic benchmarks, using a BETA BUILD of fennecs. Real-world performance will vary wildly. If you need a production-ready ECS today, 9 out of 10 foxes endorse Friflo.Engine.ECSπŸ‘ and Flecs.NETπŸ‘

Another optimization pass for fennecs is on the Roadmap.

Benchmark: CreateEntityWithThreeComponents

// Benchmark Process Environment Information:
// BenchmarkDotNet v0.13.12
// Runtime=.NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
// GC=Concurrent Workstation
// HardwareIntrinsics=AVX2,AES,BMI1,BMI2,FMA,LZCNT,PCLMUL,POPCNT VectorSize=256
// Job: ShortRun(IterationCount=3, LaunchCount=1, WarmupCount=3)
// [EntityCount=100_000]
ECS & MethodDuration<br/>(less=better)
🦊 fennecs1.458 ms
FrifloEngineEcs1.926 ms
LeopotamEcs4.991 ms
LeopotamEcsLite4.994 ms
Arch7.811 ms
FlecsNet17.838 ms
DefaultEcs19.818 ms
TinyEcs24.458 ms
HypEcs25.215 ms
MonoGameExtended27.562 ms
Myriad28.249 ms
SveltoECS52.311 ms
Morpeh_Stash64.930 ms
RelEcs65.023 ms
Morpeh_Direct131.363 ms

Benchmark: SystemWithThreeComponents

// Benchmark Process Environment Information:
// BenchmarkDotNet v0.13.12
// Runtime=.NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
// GC=Concurrent Workstation
// HardwareIntrinsics=AVX2,AES,BMI1,BMI2,FMA,LZCNT,PCLMUL,POPCNT VectorSize=256
// Job: ShortRun(IterationCount=3, LaunchCount=1, WarmupCount=3)
// [EntityCount=100_000, EntityPadding=10]
ECS & MethodDuration<br/>(less=better)Comment
🦊 fennecs(AVX2)10.43 ¡soptimized Stream<>.Raw using AVX2 Intrinsics
🦊 fennecs(SSE2)11.41 ¡soptimized Stream<>.Raw using SSE2 Intrinsics
FrifloEngineEcs_MultiThread13.45 Β΅s
FrifloEngineEcs_SIMD_MonoThread16.92 Β΅s
TinyEcs_EachJob20.51 Β΅s
Myriad_MultiThreadChunk20.73 Β΅s
TinyEcs_Each40.84 Β΅s
FrifloEngineEcs_MonoThread43.41 Β΅s
HypEcs_MonoThread43.86 Β΅s
🦊 fennecs(Raw)46.36 ¡sstraightforward loop over Stream<>.Raw
HypEcs_MultiThread46.80 Β΅s
Myriad_SingleThreadChunk48.56 Β΅s
Arch_MonoThread51.08 Β΅s
Myriad_SingleThread55.65 Β΅s
🦊 fennecs(For)56.32 ¡syour typical bread & butter fennecs workload
Arch_MultiThread59.84 Β΅s
FlecsNet_Iter77.47 Β΅s
🦊 fennecs(Job)97.70 ¡sunoptimized in beta, ineffective <1M entities
DefaultEcs_MultiThread102.37 Β΅s
Myriad_Delegate109.31 Β΅s
Arch_MonoThread_SourceGenerated134.12 Β΅s
DefaultEcs_MonoThread142.35 Β΅s
LeopotamEcs181.76 Β΅s
FlecsNet_Each212.61 Β΅s
LeopotamEcsLite230.50 Β΅s
Myriad_Enumerable245.76 Β΅s
RelEcs250.93 Β΅s
SveltoECS322.30 Β΅sEntityPadding=0, skips benchmark with 10
MonoGameExtended387.12 Β΅s
Morpeh_Stash992.62 Β΅s
Myriad_MultiThread1115.44 Β΅s
Morpeh_Direct2465.25 Β΅s

πŸ₯Š Comparisons: Punching above our weight?

So how does fennecs compare to other ECSs?

This library is a tiny, tiny ECS with a focus on good performance and great simplicity. But it cares enough to provide a few things you might not expect.

[!IMPORTANT] The idea of fennecs was to fill the gaps that the author felt working with various established Entity-Component Systems. This is why this matrix is clearly imbalanced, it's a shopping list of things that fennecs does well and was made to do well; and things it may aspire to do but compromised on in order to be able to achieve the others.

<em>(TL;DR - Foxes are soft, choices are hard - Unity dumb, .NET 8 really sharp.)</em>

<details> <summary>πŸ₯‡πŸ₯ˆπŸ₯‰ (click to expand) ECS Comparison Matrix<br/><b></b></summary>

Here are some of the key properties where fennecs might be a better or worse choice than its peers. Our resident fennecs have worked with all of these ECSs, and we're happy to answer any questions you might have.

fennecsHypEcsEntitasUnity DOTSDefaultECS
Boilerplate-to-Feature Ratio3-to-15-to-112-to-127-to-1 😱7-to-1
Entity-Component Queriesβœ…βœ…βœ…βœ…βœ…
Entity-Entity Relationsβœ…βœ…βŒβŒβœ…<br/><sup>(Map/MultiMap)</sup>
Entity-Object-Relationsβœ…πŸŸ¨</br><sup>(System.Type only)</sup>❌❌❌
Target Querying<br/><sup>(find all targets of specific relations)</sup>βœ…βŒβŒβŒβœ…
Wildcard Semantics<br/><sup>(match multiple relations in 1 query)</sup>βœ…βŒβŒβŒβŒ
JournalingβŒβŒπŸŸ¨βœ…βŒ
Shared Componentsβœ…<br/><sup>(ref types only)</sup>❌❌🟨<br/><sup>(restrictive)</sup>βœ…
Mutable Shared Componentsβœ…βŒβŒβŒβœ…
Reference Component Typesβœ…βŒβŒβŒβŒ
Arbitrary Component Typesβœ…βœ…<br/><sup>(value types only)</sup>βŒβŒβœ…
Structural Change Events🟨<br/><sup>(planned)</sup>βŒβœ…β˜ οΈ<br/><sup>(unreliable)</sup>❌
Workload SchedulingβŒβŒβŒβœ…<br/><sup>(highly static)</sup>βœ…
No Code Generation Requiredβœ…βœ…βŒβŒπŸŸ¨<br/><sup>(roslyn addon)</sup>
Enqueue Structural Changes at Any Timeβœ…βœ…βœ…πŸŸ¨<br/><sup>(restrictive)</sup>🟨
Apply Structural Changes at Any TimeβŒβŒβœ…βŒβŒ
Parallel Processing⭐⭐⭐❌⭐⭐⭐⭐⭐
Singleton / Unique Components🟨<br/><sup>(ref types only)</sup>βŒβœ…πŸŸ¨<br/><sup>(per system)</sup>βœ…
</details>

🧑 Acknowledgements

Many thanks to Byteron (Aaron Winter) for creating HypEcs and RelEcs, the inspiring libraries that fennecs evolved from.

Neofox was created by Volpeon and is in the Creative Commons CC BY-NC-SA 4.0, the same license applies to all Neofox-derived works made for this documentation.