Relationships
#5254 build: bundle @opentelemetry, @babel and beautiful-mermaid into swamp's own chunks to cut about 19 MB from the binary
Opened by skunk-ape · 11/30/2026
Problem
The compiled binary embeds every npm dependency as its whole package folder: source maps, CommonJS copies, type declarations and all. The bundled build keeps every npm package external, so none of them is trimmed to the code swamp uses. npm folders are about 52.7 MB of the binary, and most of that never runs.
#5247 added INLINED_NPM_PACKAGES to scripts/compile.ts, which bundles a listed package into swamp's own chunks. For the MCP SDK that cut its cost from 8.5 MB to 2.5 MB, with the same behaviour.
Proposed change
Add the largest packages that bundle cleanly to INLINED_NPM_PACKAGES. These estimates are from a bundle with nearly every package inlined: the folder in the binary today, minus about twice the code used, since bundled code ships its source map too.
| Package | In the binary now | Code used | Estimated saving |
|---|---|---|---|
@opentelemetry/* |
11.7 MB | 0.8 MB | ~10 MB |
@babel/* (parser, types) |
4.7 MB | 0.8 MB | ~3 MB |
@vercel/beautiful-mermaid |
2.5 MB | 0.3 MB | ~1.9 MB |
That is about 15 MB from the three. Type-only packages that ship only because something depends on them (@types/*, csstype, type-fest, up to ~4 MB) should drop out once their dependents are bundled in, for roughly 19 MB in all. Lower each target's limit in scripts/binary_size_limits.json to lock the saving in.
Out of scope
- zod. Extensions get swamp's zod through
globalThis.__swamp_zod, and that has to stay one shared copy. It stays as it is. - Packages that don't bundle as they are:
emojilib, pulled in bymarked-terminal;ink, which needsreact-devtools-core(soreact-reconcilerstays too);- a package that loads an
html_renderermodule at runtime.
- Uncertain measurements.
protobufjs(2.9 MB) andes-toolkit(2.0 MB) showed almost no used code. Confirm that before counting on them. - The fallback build.
deno run compile --no-bundlekeeps every folder.
Risks
A file a package loads at runtime that the bundle drops fails only in the compiled binary. The type check and unit tests do not catch it. Each package needs a smoke test, on a compiled binary, of the commands that use it; for @opentelemetry that means a run that exports telemetry.
Done when
- The three packages above are inlined and the type-only packages they pull in are gone from the binary.
- The binary is at least about 15 MB smaller on every target, with the size limits lowered to match.
- A compiled-binary smoke test covers telemetry export, the TypeScript parsing paths that use
@babel, and mermaid rendering.
Open
No activity in this phase yet.
Sign in to post a ripple.