Skip to content

perf: specialize guarded ECS typed columns - #8845

Closed
proggeramlug wants to merge 1 commit into
codex/ecs-loop-guard-hoistfrom
codex/ecs-typed-array-loop-view
Closed

perf: specialize guarded ECS typed columns#8845
proggeramlug wants to merge 1 commit into
codex/ecs-loop-guard-hoistfrom
codex/ecs-typed-array-loop-view

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Summary

  • recognize the narrow call-free ECS kernel where an admitted packed entity list indexes two to four erased component locals
  • fuse source-layout and component-column admission into one runtime guard that requires exact, pairwise-distinct, equal-length owning Uint32Arrays
  • persist an exact nonnegative-integer prefix proof on the Array-subclass source and normalize its entity IDs to Perry's compact INT32 Number representation
  • install loop-local noalias Uint32 views so component reads/writes lower to direct native loads/stores, while the source loop uses one contiguous base
  • preserve out-of-bounds semantics: unequal component lengths decline the clone; an out-of-range entity on equal-length columns skips the no-effect iteration rather than replaying earlier work
  • retain the unchanged generic clone for every guard/matcher miss

This is stacked on #8839. Once #8839 lands, this PR can be retargeted to main without changing its diff.

Why

After #8839, the Wolf ECS hot loop still paid erased TypedArray receiver/kind/data/length dispatch for every component access. The generated system kernel dominated the profile. Runtime admission can establish the stronger representation and alias facts once, allowing the loop itself to operate on raw Uint32 lanes.

The final AArch64 inner loop is reduced to one compact entity-id load, one component bound check, two component loads, two stores, and integer induction/control.

Performance

Pinned Mac mini, unchanged noctjs/wolf-ecs/simple_iter oracle, precompiled full-runtime binaries (--no-auto-optimize), taskpolicy -t 0 -l 0:

cohort median ms/op result
#8839-era guarded-loop control ~0.0705 baseline
this branch, regenerated 0.005281 ~13.3x faster / ~92.5% lower latency
Node v26.5.1, fresh 5-process sample 0.005124 Perry is ~3.1% behind

Cleanup A/B against the retained v10 mechanism artifact was neutral, as expected: 0.005281 vs 0.005276 ms/op (-0.10%, noise), 16/16 semantic oracles, identical 207,847,424-byte max RSS. The fresh Node cohort passed 8/8 semantic oracles.

The quick cohorts intentionally used a one-sample idle gate and are development evidence, not a strict publication-quality run. JSON artifacts and binaries were retained locally under /private/tmp/perry-ecs-artifacts-8772.

Validation

  • cargo fmt --all
  • git diff --check
  • cargo check --release -p perry-codegen -p perry-runtime
  • cargo test --release -p perry-runtime --lib array::subclass_tests -- --nocapture (10/10)
  • full Wolf semantic/rate oracle from a matching full-runtime build
  • alternating 5-pair mechanism A/B (16/16 oracle executions)
  • fresh 5-process Node cohort (8/8 oracle executions)

Follow-up

The remaining measured gap is only ~3%. The next useful optimization is backend-level control-flow amortization: emit the already-matched swap kernel directly (or attach loop-specific LLVM unroll metadata) so it can be unrolled/software-pipelined without lowering the HIR body twice. A manual HIR-body duplication experiment was rejected because it perturbed compiler fact state outside the kernel; no part of that experiment is included here.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3454961a-2e74-4a91-b93d-20d8eef264e7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

proggeramlug added a commit that referenced this pull request Aug 26, 2026
* docs: design Node-API host

* perf: reuse guarded ECS entity indices

* fix(runtime): reject oversized generic slice results

* perf: specialize guarded ECS typed columns

* chore: batch-landing fixes (per-arm GC store markers, index_set packed-loop split)

---------

Co-authored-by: Ralph Kuepper <ralph@skelpo.com>
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via the #8847 batch.

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