Skip to content

perf: remove residual Wolf ECS admission overhead - #8848

Closed
proggeramlug wants to merge 2 commits into
mainfrom
codex/ecs-hot-loop-followups
Closed

perf: remove residual Wolf ECS admission overhead#8848
proggeramlug wants to merge 2 commits into
mainfrom
codex/ecs-hot-loop-followups

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cache successful owning Uint32Array admissions in the existing direct-mapped TypedArray cache and invalidate the entry whenever the live receiver ceases to satisfy that ownership contract
  • fast-path Array-subclass .length misses through the existing exact-ShapeId dense-subclass proof while retaining ordinary lookup for accessors, prototype overrides, sparse layouts, and unrelated objects
  • keep both changes general and fail-closed; no upstream source, benchmark-specific name, or semantic shortcut is introduced

Why

After #8847, noctjs/wolf-ecs/simple_iter had a branch-light generated swap loop, but every invocation still paid two avoidable runtime costs:

  1. repeated owning-Uint32Array registry admission for the same component columns; and
  2. full generic object lookup for polymorphic Query / Archetype .length reads because Array subclasses use ObjectHeader, not GC_TYPE_ARRAY.

The .length miss was the material residual. The cache is a smaller supporting improvement.

Performance

Pinned Apple-silicon Mac mini, unchanged strong Wolf oracle, precompiled binaries, alternating order, taskpolicy -t 0 -l 0:

comparison control candidate result wins semantic oracles
owning-U32 admission cache vs #8847 head retained exact control retained exact candidate 0.530% paired improvement 10/15 38/38
subclass-length fast path vs cache-only 0.00525835 ms/op 0.00346675 ms/op 33.93% lower latency 9/9 26/26
final Perry vs Node 26.5.1 Node 0.00509194 ms/op Perry 0.00347725 ms/op Perry 31.81% faster 9/9 Perry 26/26

A separate aggregate entity-range proof plus explicit loop-unroll experiment was tested and rejected: its quiet-host 9-pair paired median was 0.55% worse with 4/9 wins. None of that experiment is included here.

Validation

  • cargo fmt --all -- --check
  • git diff --check
  • cargo check --release -p perry-codegen -p perry-runtime
  • cargo test --release -p perry-runtime --lib owning_u32_admission_cache_skips_registry_and_invalidates -- --nocapture
  • cargo test --release -p perry-runtime --lib array_length_fast_path_tests -- --nocapture (2/2)
  • cargo test --release -p perry-runtime --lib array::subclass_tests -- --nocapture (10/10)
  • unchanged Wolf semantic oracle in every performance process

Summary by CodeRabbit

  • Bug Fixes

    • Improved length handling for array subclasses while preserving standard object behavior.
    • Added fallback handling for unsupported array layouts.
  • Performance

    • Improved repeated Uint32Array access through caching.
    • Ensured cached results are invalidated when arrays are unregistered.
  • Tests

    • Added coverage for array subclass lengths and cache reuse/invalidation.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a3dd3c3d-0f1f-43ca-98f9-af15a27078ab

📥 Commits

Reviewing files that changed from the base of the PR and between cb9e967 and 15d7673.

📒 Files selected for processing (2)
  • crates/perry-runtime/src/object/field_get_set/ic_miss.rs
  • crates/perry-runtime/src/typedarray/mod.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The IC miss handler now supports validated length reads for array subclasses. The typed-array runtime adds a direct cache for owning Uint32Array admission checks and invalidates cached entries during unregistration.

Changes

Array subclass length lookup

Layer / File(s) Summary
Length dispatch and regression coverage
crates/perry-runtime/src/object/field_get_set/ic_miss.rs
The length fast path distinguishes genuine arrays, compatible array subclasses, and other objects. Tests cover subclass lengths and ordinary object properties.

Uint32Array admission cache

Layer / File(s) Summary
Admission cache and invalidation
crates/perry-runtime/src/typedarray/mod.rs
A direct cache stores owning Uint32Array addresses, serves repeated admissions, and invalidates entries during unregistration. Tests cover cache reuse and invalidation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 15d76

The PR makes localized runtime performance optimizations with documented validation and no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the purpose, implementation, performance results, and validation commands. It does not use every template heading, but it provides the required core information and is…
Title check ✅ Passed The title clearly identifies the performance-focused removal of residual Wolf ECS admission overhead. It covers the primary objective, although it does not mention the related Array-subclass length op…
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the purpose, implementation, performance results, and validation commands. It does not use every template heading, but it provides the required core information and is mostly complete.

Full details: Title check

Explanation

The title clearly identifies the performance-focused removal of residual Wolf ECS admission overhead. It covers the primary objective, although it does not mention the related Array-subclass length optimization.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ecs-hot-loop-followups

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
* perf: cache owning Uint32Array admissions

* perf: fast-path Array subclass length misses

* perf(codegen): route proven Array length writes

* perf(runtime): bulk-truncate ordinary dense arrays

* chore: add array truncation changelog

* runtime: add Node-API host core

* docs: add Node-API host changelog fragment

* runtime: harden Node-API host contracts

* runtime: bound Node-API UTF-16 encoding

* codegen(calls): pad under-applied same-module direct calls with undefined (#8770)

A same-module direct call with fewer arguments than the callee's declared
parameter count lowered only the provided args, leaving the remaining FP
argument registers holding caller-saved garbage — which the callee then
read as JS values. The cross-module twin (extern_func.rs, the issue #608
arm) has always padded missing trailing args with TAG_UNDEFINED; the
same-module plain arm sat "one else away" (#7154's own words) unpadded.

On the Claude Code bundle — one giant module, so EVERY direct call
resolves through the same-module arm — `aP([q])` for
`function aP(q, K = !1, _)` handed K/_ whatever d1/d2 held after
js_array_from_values: impossible-NaN bit patterns (0xffffffffffffffff)
that flowed into truthiness tests and method receivers (`_.get(A)`) and
faulted in shape_is_url_search_params / js_is_truthy (~60% of `cc -p`
runs SEGV), or silently corrupted the async iteration ("Detected
unsettled top-level await", most of the rest).

With the padding, `cc -p` runs 30/30 clean: 0 SEGV, 0 hangs, 0 unsettled
awaits, node-identical output on every run. The GC-knob correlations the
long #8770 investigation chased (scavenge pacing, conservative-scan
"fixes") were register-content side effects of the missing padding, not
collector bugs.

Regression test: an under-applied direct call to a 3-param callee must
emit all three double args, the omitted two as the TAG_UNDEFINED literal.

Claude-Session: https://claude.ai/code/session_01Ay8VyLkKbm8Hkc1xmvTEsP

* fix(async_hooks): complete node suite parity

* chore: batch-landing fixes (node-api scoped ptrs, header/ic_miss splits, fmt)

---------

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

Copy link
Copy Markdown
Contributor Author

Landed on main via the #8857 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