Archetype ECS
A high-performance, strictly-typed, archetype-based Entity Component System for Rust.
Archetype ECS differs from other Rust ECS libraries by focusing on a "pure" data-oriented design with zero "game engine" bloat. It provides a robust kernel for building complex simulations and game engines, offering industry-standard features like parallel iteration, reactive queries, and hierarchical transforms out of the box.
features
- 🚀 High Performance: Cache-friendly archetype storage with SoA (Structure of Arrays) layout.
- ⚡ Parallel Execution: Automatic multi-threaded system scheduling with dependency resolution.
- 🔍 Reactive Queries: Efficient
Changed<T>,Added<T>, andRemoved<T>filters. - 🌳 Hierarchy System: First-class parent-child relationship management with efficient transform propagation using
glam. - 💾 Serialization: Built-in JSON serialization for entities, components, and entire worlds.
- 📦 Asset Management: Typed asset handles, async-ready loaders, and hot-reloading support.
- 🧩 Modularity: Zero "engine" assumptions. Use it for rendering, physics, or data processing.
Quick Start
Add to Cargo.toml:
[]
= { = "https://github.com/saptak7777/archetype_ecs" }
= "0.25" # Recommended for math types
Basic Example
use *;
use ;
// 1. Define Components
// 2. Define a System
;
Core Concepts
World & Archetypes
Data is stored in Archetypes, grouping entities with the precise same set of components together. This guarantees contiguous memory for iteration, minimizing cache misses.
// Entities are just IDs.
let entity = world.spawn;
Queries & Filters
Queries are cached for O(1) access after the first run.
// Basic iteration
for in world.
// Mutable iteration
for in world.
// Change detection (Reactive)
for pos in world.
Hierarchy & Transforms
The hierarchy module provides optimized component-based scene graphs.
let parent = world.spawn;
let child = world.spawn;
// Attach child to parent
world.attach?;
// HierarchyUpdateSystem will automatically propagate transforms
Parallel Systems
The ParallelExecutor distributes systems across a thread pool, ensuring thread safety via runtime borrow checking.
let mut executor = new;
// Automatically runs independent systems in parallel
executor.execute_parallel?;
Performance
Archetype ECS is designed for speed.
- Iteration: Linear memory access pattern allows efficient prefetching.
- Change Detection: Bitset-based filtering makes reactive systems negligible in cost.
- Fragmentation: Archetype moves are somewhat expensive, so distinct "States" (like
WalkingvsFlyingcomponents) should be used judiciously.
(Benchmarks running on Intel Core i5-11400f, 100k entities)
- Simple Iteration: ~0.5ns / entity
- Composed Query: ~1.2ns / entity
- Parallel Dispatch: Scales linearly with cores for disjoint data.
Standard Compliance
- Math: Uses
glamfor SIMD-accelerated linear algebra. - Serialization: Uses
serdefor universal IO. - Async: Compatible with standard async runtimes for non-ECS tasks (like asset loading).
License
Apache-2.0.