Skip to content

size: per-module registry for callable-export attach decoration (stream/fs/cp/wasi/vm finally strip; hello −133 KB) - #6931

Merged
proggeramlug merged 4 commits into
mainfrom
size/callable-exports-split
Jul 28, 2026
Merged

size: per-module registry for callable-export attach decoration (stream/fs/cp/wasi/vm finally strip; hello −133 KB)#6931
proggeramlug merged 4 commits into
mainfrom
size/callable-exports-split

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Second increment of the namespace devirt (follows #6928; the mapped plan from that PR's follow-up section).

bound_native_callable_export_value's hand-written per-module attach ladder — the last static reference from the callable-exports core into every module's prototype/statics machinery — is now NM_ATTACH_REGISTRY (mirrors NM_DISPATCH_REGISTRY/NM_CTOR_REGISTRY), with 12 per-module handlers (module/tty/tls/wasi/stream/sqlite/assert/crypto/perf_hooks/async_hooks/events/util) registered by the existing js_nm_install_<module>() fns. Bodies moved verbatim; arming is sound because this path is only reachable through a module's namespace, which exists only after its install ran (plus the same #[cfg(test)] lazy-install fallback the ctor registry uses).

Measured on a hello world (default flags): 4,709,904 → 4,576,952 bytes across this branch (−133 KB with #6928's foundation); ld64 -why_live confirms js_node_stream_pipeline is now dead, and per-module attribution shows fs 161→27 KB, child_process → 0.9 KB, wasi → 0, node:vm → 6.5 KB.

Verification: differential probes byte-identical to Node (stream Readable.from iteration, pipeline[promisify.custom], events.once + EventEmitter statics incl. defaultMaxListeners, AsyncLocalStorage.bind); 12-test gap sweep byte-identical; cargo test -p perry-runtime --lib --test-threads=1: 1476/1476 (parallel runs show only the known #6926 / gc-teardown flakes).

Remaining (next increment, same recipe): the twin get_native_module_constant ladder in constants.rs — now the sole retainer of the node_submodules export tables (80 KB) and the node_stream residual (158 KB) — then Intl (219 KB, needs fallbacks) and lazy globalThis.

Summary by CodeRabbit

  • Performance
    • Reduced binary size by including only the native-module attach functionality needed by the imported modules.
    • Improved linker dead-stripping for several built-in modules.
  • Bug Fixes
    • Maintained correct native callable attachment behavior, including prototype and static property wiring for built-in modules.
  • Tests
    • Confirmed byte-identical output.
    • Ran a targeted test gap sweep and the full runtime test suite.

@coderabbitai

coderabbitai Bot commented Jul 28, 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: 2c7857ec-30b1-40a2-b3e8-04bef77ee8e9

📥 Commits

Reviewing files that changed from the base of the PR and between f872e67 and a1724a6.

📒 Files selected for processing (1)
  • crates/perry-runtime/src/object/native_module/callable_exports.rs

📝 Walkthrough

Walkthrough

Native callable attachment now uses a per-module registry. Module installers register attach handlers, and bound native callable exports look up and invoke handlers instead of using a centralized conditional ladder.

Changes

Native callable attachment

Layer / File(s) Summary
Attach registry dispatch
crates/perry-runtime/src/object/native_module.rs, crates/perry-runtime/src/object/native_module_registry.rs
Adds the attach-function contract, registry storage, lookup logic, and crate-visible callable exports.
Per-module attach handlers
crates/perry-runtime/src/object/native_module/callable_exports.rs
Routes callable export decoration through registry handlers and extracts module-specific attachment logic into nm_attach_* functions.
Module installer registration
crates/perry-runtime/src/object/native_module_registry.rs, changelog.d/6931-callable-attach-registry.md
Registers attach handlers from native module installers and documents the registry implementation and validation results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant bound_native_callable_export_value
  participant native_module_registry
  participant nm_attach_handler
  bound_native_callable_export_value->>native_module_registry: nm_attach_lookup(export_module_name)
  native_module_registry-->>bound_native_callable_export_value: registered nm_attach_* handler
  bound_native_callable_export_value->>nm_attach_handler: attach(property_name, value, closure_addr)
  nm_attach_handler-->>bound_native_callable_export_value: updated value
Loading

Suggested reviewers: thehypnoo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing, but it does not follow the required template or include the required sections. Add the template sections: Summary, Changes, Related issue, Test plan, Screenshots/output, and Checklist, using concise bullets where requested.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the main change: moving callable-export attach decoration to a per-module registry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch size/callable-exports-split

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/perry-runtime/src/object/native_module/callable_exports.rs (1)

1632-1639: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the vestigial if true &&.

Tautology left over from the ladder extraction.

♻️ Proposed cleanup
-    if true
-        && matches!(
-            property_name,
-            "Readable" | "Writable" | "Duplex" | "Transform" | "PassThrough"
-        )
-    {
+    if matches!(
+        property_name,
+        "Readable" | "Writable" | "Duplex" | "Transform" | "PassThrough"
+    ) {
         attach_stream_constructor_prototype(value, property_name);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-runtime/src/object/native_module/callable_exports.rs` around
lines 1632 - 1639, Remove the vestigial `if true &&` from the conditional
surrounding `attach_stream_constructor_prototype`, preserving the existing
`matches!` check for the stream constructor property names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-runtime/src/object/native_module/callable_exports.rs`:
- Around line 1587-1597: Rename the unused closure_addr parameter to
_closure_addr in nm_attach_tty, nm_attach_tls, nm_attach_wasi, nm_attach_stream,
nm_attach_sqlite, and nm_attach_assert. Keep each function’s signature
compatible with NmAttachFn and leave the existing value handling unchanged.

---

Nitpick comments:
In `@crates/perry-runtime/src/object/native_module/callable_exports.rs`:
- Around line 1632-1639: Remove the vestigial `if true &&` from the conditional
surrounding `attach_stream_constructor_prototype`, preserving the existing
`matches!` check for the stream constructor property names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c6d4058c-3451-41fb-ac81-fa7d13c716db

📥 Commits

Reviewing files that changed from the base of the PR and between d3593f3 and f872e67.

📒 Files selected for processing (4)
  • changelog.d/6931-callable-attach-registry.md
  • crates/perry-runtime/src/object/native_module.rs
  • crates/perry-runtime/src/object/native_module/callable_exports.rs
  • crates/perry-runtime/src/object/native_module_registry.rs

Comment thread crates/perry-runtime/src/object/native_module/callable_exports.rs
@proggeramlug

Copy link
Copy Markdown
Contributor Author

CodeRabbit's finding addressed in the latest push (_closure_addr in the six handlers that don't decorate via the closure address). The red lint is the pre-existing public-benchmark-freshness artifact on main (same as #6917/#6922/#6923).

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