Skip to content

feat(runtime): gate node:dgram behind mod-dgram (binary size)#5163

Closed
proggeramlug wants to merge 1 commit into
feat/binary-size-diagnosticsfrom
feat/binary-size-native-module-gate
Closed

feat(runtime): gate node:dgram behind mod-dgram (binary size)#5163
proggeramlug wants to merge 1 commit into
feat/binary-size-diagnosticsfrom
feat/binary-size-native-module-gate

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

What

First instance of a per-Node-module gating pattern: node:dgram (UDP sockets — crate::dgram + crate::dgram_reactor, ~43 KB incl. the js_dgram_* externs codegen emits direct calls to) is now compiled only when a program imports it.

Result

hello-world drops ~0.1 MB (dgram off). A real dgram program (createSocket/bind/send/on-message) auto-enables the feature, links + runs correctly. No speed change — pure cfg gate.

How

  • mod-dgram cargo feature (in default) gates crate::dgram + crate::dgram_reactor, the ("dgram", …) dispatch arm, and the gc_init dgram-reactor root-scanner registration.
  • The compiler detects module: "dgram" in the HIR (a dgram namespace can only arise from importing it) → ctx.uses_dgram → forwards perry-runtime/mod-dgram + cache-keys it. dgram is runtime-only, so it's not in native_module_imports (that set tracks only requires_stdlib modules) — HIR detection is the correct signal.
  • codegen only emits js_dgram_* calls for dgram programs (which get the feature on), so the off build links cleanly with no dangling symbols (verified via auto-optimize link of both a dgram program and hello-world).

Stacked on #5159 (diagnostics gate); will retarget to main after that merges.

The big remaining lever (de-coupling console/process from the monolithic dispatch_native_module_method so all dispatch-only modules dead-strip, ~400 KB) is a deeper refactor for a separate, supervised PR.

`node:dgram` (UDP sockets — `crate::dgram` + `crate::dgram_reactor`, ~43 KB
incl. the `js_dgram_*` externs codegen emits direct calls to) is now compiled
only when a program imports it. The compiler detects `module: "dgram"` in the
HIR (a dgram namespace can only arise from the import) and forwards
`perry-runtime/mod-dgram` to the auto-optimize build; a program that never
uses dgram links none of it (hello-world −~0.1 MB). No speed change.

This is the first instance of a general per-Node-module gating pattern: cfg the
module impl + its `native_module_dispatch` arm + its gc root-scanner
registration behind a `mod-<x>` feature, enabled from compile-time usage
detection. dgram is detected via HIR (it's runtime-only, so absent from
`native_module_imports`, which tracks only stdlib modules).

The dgram dispatch arm + the gc_init `dgram_reactor` root-scanner registration
are cfg-gated so the off build links cleanly; codegen only emits `js_dgram_*`
calls for dgram programs, which get the feature on, so no dangling symbols.
@coderabbitai

coderabbitai Bot commented Jun 14, 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: 6403b276-0be5-4159-abd9-bd687df47f60

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/binary-size-native-module-gate

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

@proggeramlug proggeramlug deleted the branch feat/binary-size-diagnostics June 14, 2026 22:08
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