Skip to content

Runtime Implementation (#202) - #213

Merged
nockawa merged 16 commits into
mainfrom
feature/202-runtime
Apr 2, 2026
Merged

nockawa merged 16 commits into
mainfrom
feature/202-runtime

Conversation

@nockawa

@nockawa nockawa commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Complete runtime implementation — the game server execution layer orchestrating tick-based simulation, system scheduling, parallel dispatch, client subscriptions, and overload management.

Sub-issues completed

Parallel dispatch optimization (#211 — bulk of recent work)

Rewired parallel QuerySystem dispatch to eliminate two bottlenecks:

O(N) entity list materialization → O(1): PartitionEntityView wraps HashMap.GetPartitionEnumerator() for zero-copy bucket-range iteration. No array copy in prepare phase.

Per-chunk Transaction overhead → eliminated: PointInTimeAccessor with Attach() pattern provides per-worker EntityAccessor instances via flat array (zero per-entity dictionary overhead). Warm ChunkAccessor page caches persist across ticks.

Four dispatch paths based on WritesVersioned × HasChangeFilter:

  1. Full + Non-Versioned: O(1) prepare, PTA + PartitionEntityView
  2. Filtered + Non-Versioned: O(dirty) prepare, PTA + PooledEntitySlice
  3. Full + Versioned (fallback): O(N) prepare, per-chunk Transaction
  4. Filtered + Versioned (fallback): O(dirty) prepare, per-chunk Transaction

Additional performance optimizations (found via profiling)

  • Cached EntityMap ChunkAccessor in ResolveEntity — eliminated ~120ns/entity from creating fresh accessor per Open()
  • Skip EpochGuard when already in epoch scope (PTA workers)
  • Interlocked DirtyCounter — replaced AccessControlSmall spinlock with single atomic ops
  • Array-indexed ComponentInfo — O(1) flat array lookup alongside Dictionary
  • WalkChain single-entry fast-path — skips RevisionEnumerator construction for 95%+ of entities (35% savings on Versioned reads)
  • ResetForNewSnapshot zero-alloc iteration — flat array instead of Dictionary.Values

Benchmark results (AMD Ryzen 7950X, 32 cores)

Metric Before After
Per-entity overhead 535ns 370ns (30% reduction)
CPU-bound 8 workers 4.53x (57%) 7.10x (89%)
Write scaling 28 workers 1.47x 4.25x
Per-chunk PTA vs Transaction 1.02x 2.2x

Deferred

Test plan

  • 2874 unit tests passing (1 pre-existing flaky: telemetry latency threshold)
  • 35 parallel query tests + 26 PTA tests
  • Comprehensive --parallel-dispatch benchmark (V/SV/T scaling, WalkChain micro-bench)
  • Full code review: race condition fix (per-system PTA), dispose ordering, cached delegate, OnFirstTick retry fix

139 files changed, 19,172 insertions, 806 deletions

@nockawa
nockawa merged commit 93fc4c2 into main Apr 2, 2026
5 checks passed
@nockawa
nockawa deleted the feature/202-runtime branch April 2, 2026 22:09
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.

1 participant