Skip to content

perf(runtime): compress array forwarding chains - #8674

Closed
proggeramlug wants to merge 2 commits into
perf/method-name-prototype-guardfrom
perf/array-forwarding-path-compression
Closed

perf(runtime): compress array forwarding chains#8674
proggeramlug wants to merge 2 commits into
perf/method-name-prototype-guardfrom
perf/array-forwarding-path-compression

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • compress a validated multi-hop array-growth forwarding chain at its retained head
  • keep corrupt/untracked/cyclic chains fail-closed by rewriting only after the resolver reaches a tracked live array
  • add a focused regression test and update the existing three-growth forced-minor-GC coverage for the compression contract

Why

Array growth preserves stale aliases with forwarding stubs. A receiver retained across multiple capacity-crossing grows can therefore point through two or more stubs. Generated indexed-access guards intentionally heal one forwarding edge inline; after that single hop they still see GC_FLAG_FORWARDED, reject the array guard, and enter generic indexed lookup on every access.

clean_arr_ptr already performs the complete bounded, tracked-array-validated walk. Once that walk succeeds, this change points the original retained stub directly at the live head. Subsequent generated accesses then need only their existing one-hop healing path. This is central forwarding metadata maintenance rather than an ECS- or benchmark-specific shortcut.

This PR is stacked on #8672. Please review/merge that PR first; the runtime and test change is commit 514e0f553, followed only by its changelog fragment.

Correctness

  • cargo fmt --all -- --check
  • cargo test -p perry-runtime: 2,644 passed, 0 failed, 4 ignored
  • focused multi-hop compression regression: passed
  • existing three-growth + forced minor-GC regression: passed
  • end-to-end 10k-element alias/growth fixture matched Node exactly in normal Perry execution and with PERRY_GC_FORCE_EVACUATE=1 PERRY_GC_VERIFY_EVACUATION=1
  • all 88 benchmark processes below passed the upstream 7/7 suite oracle and exact 50,005,000 accumulation checksum where applicable

The complete ECS suite under forced evacuation verification still reports the same pre-existing stale heap-field pointer failure on both the #8672 control and this candidate. Normal ECS execution passes, and the focused forced-evacuation fixture plus runtime GC regression pass.

Performance

Apple M1 Mac mini, AC power, Node 26.5.1. Each comparison followed a 60-sample quiet-host gate (all samples at or below 25% active CPU), used taskpolicy -t 0 -l 0, alternated process order, and ran 11 pairs.

Against the unchanged #8672 binary (repeat=64):

codehz/ecs kernel #8672 median candidate median median paired reduction wins
10k read-only query 1.79858 ms/op 0.32485 ms/op 81.94% 11/11
10k accumulation query 1.15038 ms/op 0.26945 ms/op 76.59% 11/11

Directly against Node 26.5.1 (repeat=256):

codehz/ecs kernel Node median Perry median median paired Perry/Node ratio
10k read-only query 0.05228 ms/op 0.32832 ms/op 6.282x
10k accumulation query 0.08646 ms/op 0.27032 ms/op 3.127x

This removes the repeated generic indexed-lookup pathology. It is a large improvement, but it does not claim Node parity; the remaining steady-state generated loop cost is separate follow-up work.

@coderabbitai

coderabbitai Bot commented Aug 24, 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: abafd49c-820b-4dcb-b506-24843f76ea29

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 24, 2026
…ape guards (#8682)

Lands three reviewed PRs as one squash: #8674, #8675, #8676.

- #8674: compress array forwarding chains (`clean_arr_ptr` multi-hop walk).
- #8675: share numeric guards across dynamic add trees.
- #8676: pack monomorphic method shape guards.

These three were authored as a stack on top of #8672, but their contents
touch disjoint files, so they are cherry-picked onto main on their own.
#8672 is NOT included: it defines its own
`is_bound_native_method_closure_value` (true for any bound native-module
export with a non-empty module name), which #8662 superseded on main with
the strictly narrower `is_bound_native_constructor_closure_value` (gated
on explicit constructor metadata). Those predicates have different truth
sets, so the substitution is a behavioural change at every call site and
is left to the author to rebase.

Also splits `array/tests.rs`, which #8674 pushed over the 2000-line cap,
into an `array/forwarding_tests.rs` sibling. Pure relocation.

Version bump not included per maintainer policy.

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via #8682 (squash 67f3f7501).

Your branch was stacked on #8672, but the contents touch disjoint files, so this commit was cherry-picked onto main on its own — #8672 itself is held pending a rebase (details on that PR).

Validated on the merged result: 9 ratchet gates + cargo fmt --check pass, perry-codegen --lib 1198/0, perry-runtime --lib 2652/0 at RUST_TEST_THREADS=1.

One adjustment: #8674's new test pushed array/tests.rs from 1998 to 2034 lines, past the 2000-line gate, so the growth-forwarding group was relocated into an array/forwarding_tests.rs sibling (matching the existing subclass_tests pattern). Pure relocation — all 5 moved tests verified still running. Thanks!

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