Repository navigation
[M1-ECS-03] Archetype SoA storage - #18
Merged
Merged
Conversation
Archetype = ordered component set stored SoA (one packed T[] column per component, rows in ascending slot-id order); entity->archetype map as two dense per-slot tables (archetypeOf_ + rowOf_, no hash); O(1) get<T>/has<T>; addComponent<T> create-or-update / removeComponent<T> no-op-ok with pool-backed moves (tail memmove + rowOf_ re-sync) and zero heap allocation per operation (bounded reserve policy: min(16,capacity) initial, x2 growth capped at world capacity, accounted + logged). Budgets: kMaxArchetypes=256, kMaxArchetypeComponents=32 (BudgetExhausted + rate-limited warns ecs/archetype_budget, ecs/component_limit). Per-slot bookkeeping 5 -> 11 B; destroy/clear detach rows first (documented cost). 25 test cases in the 'archetype' CTest entry, incl. the 10k-entity churn (20k add/remove ops, seeded random order: zero failures, zero reservation delta, zero process-wide allocations via test-only operator new counter, p99/p50 ~ 1.98, machine-greppable stats line per ctest run). Docs: docs/api/archetype.md (+ cross-refs), laige-api.json regenerated (443 symbols), roadmap checkbox + Progress Board 3/25 + Change Log. Verify: canonical g++ tree zero-warning, full ctest 36/36, ctest -R archetype green, sim suites green on build-asan/build-clang/build-release/build-shared/ build-tsan, tools/laige-include-lint OK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M1-ECS-03 · Archetype SoA storage
Implements
roadmap/M1-heartbeat.mdM1-ECS-03 (scope only — no query API,no iteration, no G-R4 thresholds):
T[]column per component, rows kept in ascending slot-id order (a pure
function of the world state; the convergence property M1-ECS-05 will
iterate).
archetypeOf_2 B +rowOf_4 B; no hash) →get<T>(e)/has<T>(e)are O(1).addComponent<T>(e, v)create-or-update /removeComponent<T>(e)no-op-ok: pool-backed moves (tail memmove +
rowOf_re-sync) withzero heap allocation per operation — bounded reserve policy
(initial
min(16, capacity)rows, ×2 growth capped at world capacity,every reserve accounted + logged;
log2(capacity/16)+1bounded).kMaxArchetypes= 256 /kMaxArchetypeComponents= 32(
BudgetExhausted+ rate-limited warnsecs/archetype_budget,ecs/component_limit); unregistered type →InvalidArgument+ecs/component_unregistered; stale handle → the M1-ECS-01 contract.entity.mdupdated);destroy/cleardetach rows first (documented O(tail × row-stride) cost, no allocation).
Tests —
archetypeCTest entry, 25 cases: basics, stale/unregisteredmatrix, layout properties (per-column contiguity, 32 B alignment,
slot-ordered addresses, shift semantics), move data preservation,
two-world layout convergence, budget boundaries (256 sets / 32 components /
growth cap at odd capacity), warn-once rate-limit summary, stats/bytes
tracking, and the 10k-entity churn: 20k add/remove ops in seeded random
order — zero failures, zero reservation delta, zero process-wide
allocations (test-only
operator newcounter on non-sanitizer trees;sanitizer trees prove it leak-free), p99/p50 ≈ 1.98 (flat), and a
machine-greppable
archetype-churn <stats>line on every ctest run(CORE-001). Measured baseline (g++ 16.2.1, single-threaded headless):
Debug p50 0.123 ms/op, Release p50 0.0021 ms/op.
Docs: new
docs/api/archetype.md(contract + Performance section),cross-refs in
entity.md/component_registry.md/ docs index / simREADME;
laige-api.jsonregenerated (443 symbols); roadmap checkbox,Progress Board 3/25, one-line Change Log.
Verify: canonical g++ tree zero-warning; full
ctest36/36;ctest -R archetypegreen; sim suites green onbuild-asan(ASan+UBSan,leak-free churn),
build-clang,build-release,build-shared,build-tsan;tools/laige-include-lintOK.Base commit:
452ab86.