Skip to content

🧼 split layout and input entrypoints#37

Open
natemoo-re wants to merge 6 commits into
mainfrom
ref/opt-split
Open

🧼 split layout and input entrypoints#37
natemoo-re wants to merge 6 commits into
mainfrom
ref/opt-split

Conversation

@natemoo-re

@natemoo-re natemoo-re commented May 23, 2026

Copy link
Copy Markdown
Member

Building on #50 (brotli+z85 encoding), this PR splits the WASM compilation into two scoped modules and exposes them as separate export subpaths, enabling per-consumer dead-code elimination and per-module opt tuning.

  • WASM compilation now based on two scoped modules: module-layout.c and module-input.c
  • new ./layout and ./input export subpaths exposed via build-npm.ts, allows downstream bundlers to tree-shake
  • removed unified wasm.ts; updated .gitignore and Makefile clean targets accordingly

Per-consumer DCE

Consumer that import only one subpath no longer need to load the other module's WASM.

consumer unified (main) split Δ
clayterm/input 43.0 kB 3.7 kB −91%
clayterm/layout 43.0 kB 39.2 kB −9%

Full bundle (JS + WASM), gzipped: input-only 47.8 kB → 8.5 kB (−82%); layout-only 48.8 kB → 45.4 kB (−7%).

Honest size note

Now that brotli+z85 (#50) is on main, the split does not reduce total install size. mem/utf8/wcwidth are duplicated across both modules, so the combined WASM is ~equal (42.1 kB split vs 42.4 kB unified, brotli) and the full package is marginally larger (115.4 kB → 121.5 kB unpacked, +5.3%). The wins here are scoping and per-module tunability, not aggregate size. Narrower compilation units also let --gc-sections apply more aggressive DCE per module.

@pkg-pr-new

pkg-pr-new Bot commented May 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tty@37

commit: ec811d0

@natemoo-re natemoo-re changed the title ref(wasm): split layout and input entrypoints 🧼 split layout and input entrypoints May 23, 2026

@ghostdevv ghostdevv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are quite a few references to both wasm.ts and clayterm.wasm still

@natemoo-re natemoo-re force-pushed the ref/opt-split branch 2 times, most recently from a4e9caf to 0c58432 Compare May 24, 2026 02:24
@natemoo-re natemoo-re force-pushed the ref/opt-split branch 2 times, most recently from 31d049e to 0bbf6d0 Compare May 24, 2026 17:37
Base automatically changed from ref/opt to main May 26, 2026 22:48

@cowboyd cowboyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. So tiny! 🤩

@natemoo-re

Copy link
Copy Markdown
Member Author

@cowboyd ah I need to rerun those numbers after rolling back the more aggressive stuff! still tiny but not quite this tiny (yet)

@codspeed-hq

codspeed-hq Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 10 untouched benchmarks


Comparing ref/opt-split (ec811d0) with main (35ce6a0)

Open in CodSpeed

@cowboyd

This comment was marked as outdated.

@natemoo-re natemoo-re requested a review from ghostdevv June 1, 2026 19:00
natemoo-re added a commit that referenced this pull request Jun 2, 2026
The opt-flags split defaulted input.wasm to -Oz (optimize for size),
which ~2x'd instruction counts on the hot parse paths (multi-byte UTF-8
decode, Kitty CSI-u trie). CodSpeed flagged UTF-8 3/4-byte and Kitty
regressions on PR #37. -O2 restores parse speed for +1557 bytes raw /
+290 bytes gzip on a 9KB module — a negligible size cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Size Increased — +8.0 KB

132.2 KB unpacked

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.

4 participants