Archetype ECS
A high-performance Entity Component System (ECS) library for Rust.
Key Features
- Efficient Asset Management: Lock-free, concurrent asset cache with LRU eviction policy.
- Change Detection: Efficient
Changed<T>andAdded<T>component filters with zero-cost skipping. - SIMD Chunk Iteration: High-performance
par_for_each_chunkAPI for maximizing CPU throughput. - Optimized for Concurrency: Built-in support for parallel query execution using Rayon.
Installation
[]
= "1.1.5"
Quick Start
use *;
// Components are plain structs
Querying Entities
Basic Queries
// Mutable query - use .iter() or IntoIterator
let mut query = world.;
for in query.iter
// Or directly (IntoIterator)
for in world.
Getting Entity IDs
Use the Entity marker to get entity IDs during iteration:
use *;
let mut to_delete = Vecnew;
for in world.
// Delete entities after iteration
for entity in to_delete
Mixed Mutability
Read some components while writing others:
// Read Position, write Velocity
for in world.
Direct Component Access
Access components on a specific entity:
// Immutable access
if let Some = world.
// Mutable access
if let Some = world.
Resources (Global State)
Resources are typed singletons for global state:
// Insert resource
world.insert_resource;
// Read resource
if let Some = world.
// Mutate resource
if let Some = world.
Query Filters
Filter entities by component presence:
use ;
// Only entities WITH a Visible component
let query = new;
for pos in query.iter
// Only entities WITHOUT a Dead component
let query = new;
// Only entities where Position changed this frame
let query = new;
Systems & Scheduling
use ;
use TypeId;
;
Parallel Execution
use ParallelExecutor;
let systems: = vec!;
let mut executor = new;
executor.execute_parallel?;
SIMD & Chunk Processing
Process entities in parallel with SIMD-friendly access:
let mut query = world.;
query.par_for_each_chunk;
Batch Operations
// Spawn many entities efficiently
let entities = world.spawn_batch?;
Performance
| Operation | Time | Scale |
|---|---|---|
| Query Iteration (Cached) | ~1.6 ns / entity | 100,000 entities |
| Query Iteration (SIMD) | ~0.54 ns / entity | 100,000 entities |
| Entity Spawn | ~86 ns / entity | 100,000 entities |
| Parallel Execution | 3.1 ms (Total) | Multi-core |
Test Environment: Intel Core i5-11400F, Intel Arc A380, 16GB RAM. Benchmarks run on v1.1.5.
License
Copyright 2024 Saptak Santra. Licensed under Apache-2.0.