Skip to content

🧼 split layout and input entrypoints#37

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

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

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

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

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
Copy link
Copy Markdown

pkg-pr-new Bot commented May 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/clayterm@37

commit: 51f4d26

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

@ghostdevv ghostdevv left a comment

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
Copy link
Copy Markdown
Collaborator

@cowboyd cowboyd left a comment

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
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 28, 2026

Merging this PR will degrade performance by 30.86%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 16 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation UTF-8 3-byte character 85 µs 176.6 µs -51.86%
Simulation UTF-8 4-byte emoji 85.5 µs 173.2 µs -50.62%
Simulation Kitty protocol (CSI u with modifiers) 97.6 µs 185.5 µs -47.38%
Simulation long input burst (200 bytes) 979.3 µs 536.1 µs +82.66%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ref/opt-split (51f4d26) with main (ebaf397)

Open in CodSpeed

@cowboyd

This comment was marked as outdated.

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