Skip to content

build: ship each verbatim runtime module once - #423

Draft
danfry1 wants to merge 1 commit into
mainfrom
build/dedupe-runtime-modules
Draft

danfry1 wants to merge 1 commit into
mainfrom
build/dedupe-runtime-modules

Conversation

@danfry1

@danfry1 danfry1 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Summary

Each runtime module now ships once, which takes about 18 KB packed and 63 KB unpacked off the package.

Why

The runtime .mjs files under src/ are copied into dist as-is, because Node loads them as files. Fourteen of them were also inlined into the bundled entries and chunks, so the package shipped their code twice and a process could hold two instances of each. Packed headroom was down to 3% against the 5% budget policy.

Changes

  • tsdown.config.ts marks every verbatim-copied .mjs as never bundled. The bundles now import the shipped file. One predicate decides both what is copied and what stays external.
  • Budget ceilings drop to about 5% above the new artifact: 112 files, 374,295 packed and 1,283,041 unpacked bytes, down from 114, 392,262 and 1,345,796.
  • New tests/verbatim-runtime-once.test.ts fails if a verbatim-shipped module is inlined into a bundle again, or if an emitted relative import does not resolve inside dist.

Notes

  • helpers.cjs now loads errors.mjs through require(esm). Every Node version in engines supports this, and 22.13.0 loads it without a warning.
  • The copies shared no state that relied on being separate. Cross-copy state already used Symbol.for, and errors are checked by shape, not instanceof.
  • src/plugin.ts still has its own versions of packageNameOf, subpathLeafOf and isUtilitySubpath from native/match.mjs. That source-level duplication is out of scope here.
  • Lands after 0.14.0.

Fourteen runtime .mjs files that ship verbatim were also inlined into the
bundled entries and chunks. tsdown now leaves them external, so the entries
import the shipped file: one module instance and about 18 KB less packed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:performance Speed, memory and per-file cost

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant