Start

friflo ECS, a small and high-performance C# ECS - Entity Component System. Its an archetype based ECS with focus on performance and simplicity.

🛈 What is an Entity Component System?

An Entity Component System (ECS) is a software architecture pattern. Wikipedia. It is often used in software development for Games, Simulation, Analytics and In-Memory Database providing high performant data processing.

An ECS has two major strengths:

  1. It enables writing highly decoupled code. Data is stored in Components which are assigned to objects - aka Entities - at runtime. Code decoupling is accomplished by dividing implementation in pure data structures (Component types) - and code (Systems) to process them.

  2. It provides high performant query execution by storing components in continuous memory to leverage L1 CPU cache and its prefetcher. It improves CPU branch prediction by minimizing conditional branches when processing components in tight loops.Data-oriented design ⋅ Wikipedia.

Design goals

🔥 High Performance

Optimal and efficient query / system execution. Fast entity creation and component changes.

🎯 Simple

Simple API - convenient to debug. No boilerplate code.

🔄 Low memory footprint

Minimal heap allocations at start phase. No heap allocations after internal buffers grown large enough. No GC pauses / no frame drops.

🛡️ Reliable

100% verifiably safe C#. No unsafe code or native bindings. Full test coverage. Expressive runtime errors. Actively maintained. Your code requires no Unsafe quirks for maximum performance.

🤏 Small

Friflo.Engine.ECS.dll size: only 320 kb. No code generation. No 3rd party dependencies.

Overview

A common ECS provide the basic features listed bellow. To solve other common use-cases not covered by basic implementations this ECS provide the listed extensions.

Basic features

An ECS acts like an in-memory database and stores entities in an EntityStore aka World. An Entity is a value type - aka struct - with a unique Id.

Data is stored in Components added to entities. Components are stored highly packed in continuous memory.

The major strength of an archetype based ECS is efficient and performant Query execution. Query filters are used to reduce the amount of components returned by the query result.

Extended features

Support Events to subscribe entity changes like adding or removing components. Event handlers can be added to a single Entity or the entire EntityStore.

Index / Search to enable lookup entities with specific component values. v3.0.0 A lookup for a specific component value - aka search - executes in O(1) ~ 4 ns. Possibly the first and only ECS that supports indexing.

Relationships to create links between entities. v3.0.0 A link is directed and bidirectional. Deleting source or target entity removes a link.

Relations to add multiple "components" to an entity. v3.0.0 Relations are not implemented as components to avoid archetype fragmentation.

Systems are optional. They are used to group queries or custom operations. They support logging / monitoring of execution times and memory allocations in realtime.

Hierarchy / Scene tree used to setup a child/parent relationship between entities. An entity in the hierarchy provide direct access to its children and parent.

JSON Serialization to serialize entities or the entire EntityStore as JSON.

Library

100% verifiably safe 🔒 C#. No unsafe code or native bindings. This prevents segmentation faults or access violations crashing a process instantaneously.

Minimal heap allocations. After internal buffers grown large enough no heap allocation will occur. At this point no garbage collection will be executed. This avoids frame stuttering / lagging caused by GC runs. Especially no allocation when

  • Creating or deleting entities

  • Adding or removing components / tags

  • Adding or removing relations or relationships

  • Emitting events

  • Changes in entity hierarchy

  • Query or system execution

Aims for 100% test coverage: Code coverage:

Project

Release Notes - document all nuget releases.

Library describes assembly specific characteristics.

Unity Extension with ECS integration in Unity Editor.

GitHub: https://github.com/friflo/Friflo.Engine.ECS

Discord: friflo ECS

Benchmark: C# ECS Benchmarks

GitHub

💖 In case you like this project? Leave a ⭐ on GitHub ⋅ friflo/Friflo.Engine.ECS

Last updated