Skip to content

feat(ecs): parallel system execution with rayon thread pool#155

Merged
iverly merged 4 commits intomainfrom
feat/parallel-ecs-dispatch
Apr 20, 2026
Merged

feat(ecs): parallel system execution with rayon thread pool#155
iverly merged 4 commits intomainfrom
feat/parallel-ecs-dispatch

Conversation

@iverly
Copy link
Copy Markdown
Contributor

@iverly iverly commented Apr 20, 2026

Summary

  • Add dependency graph scheduler that groups non-conflicting ECS systems for parallel execution during the SIMULATE phase, with a precomputed GroupCache (LCM-based cycle, O(1) per-tick lookup)
  • Implement ParallelSystemContext using store partitioning (write-stores as exclusive ownership, read-stores as shared refs) with deferred spawn/despawn
  • Integrate rayon thread pool initialization at server startup with configurable thread count (system_threads in [server.performance])
  • Add missing component access declarations on core systems (lifetime, pickup_delay)
  • Zero per-tick allocation via Vec<Option<SystemDescriptor>> storage and cache take/put-back pattern
  • Fast path for single-system groups skips all parallel machinery (zero overhead)

Closes #123

Test plan

  • 43 unit/integration tests in basalt-ecs (schedule groups, ParallelSystemContext, parallel dispatch with conflicting/non-conflicting systems, deferred spawn, run_all integration, read+write cross-system)
  • 68 basalt-server tests pass (backward compatibility)
  • Full workspace test suite green (0 failures)
  • clippy clean (-D warnings)
  • fmt clean
  • Run nightly benchmarks: cargo +nightly bench -p basalt-ecs to establish baseline for parallel_fast_path, parallel_3_non_conflicting, parallel_2_conflicting

iverly added 4 commits April 20, 2026 20:29
Rayon will be used for parallel ECS system dispatch during the
SIMULATE phase. Added as a workspace dependency and wired into
basalt-ecs and basalt-server.
Add dependency graph scheduler and parallel dispatch for the SIMULATE
phase. Non-conflicting systems run concurrently via rayon; conflicting
systems are serialized into sequential groups.

Key components:
- schedule.rs: greedy graph coloring from SystemAccess declarations,
  with GroupCache precomputed at startup (LCM-based cycle, O(1) lookup)
- parallel.rs: ParallelSystemContext using store partitioning —
  write-stores as exclusive ownership, read-stores as shared refs
- ecs.rs: run_phase_parallel with fast path for single-system groups,
  zero per-tick allocation via Vec<Option<SystemDescriptor>> storage

Spawn/despawn during parallel execution is deferred and applied
between groups. The SystemContext trait and all plugin APIs are
unchanged.
Initialize the rayon global thread pool at server startup with a
configurable thread count (system_threads in [server.performance]).
Add missing component access declarations on core systems (lifetime,
pickup_delay) so the parallel scheduler can compute correct groups.
Three nightly benchmarks for regression detection:
- fast path (single system, zero overhead baseline)
- 3 non-conflicting systems (rayon parallel dispatch)
- 2 conflicting systems (sequential fallback in separate groups)
@iverly iverly merged commit f1822bf into main Apr 20, 2026
22 checks passed
@iverly iverly deleted the feat/parallel-ecs-dispatch branch April 20, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ecs): parallel system execution with rayon thread pool

1 participant