Skip to content

🧼 optimize install size#35

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

🧼 optimize install size#35
natemoo-re wants to merge 11 commits into
mainfrom
ref/opt

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

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

Reduces npm install size by 63% (723kB → 268kB unpacked) via:

  • optimizing clang build flags with explicit exports and dead code elimination
  • stripped source maps and src/ duplication from the npm package

Also bumps minimum node version to v22 (current LTS).

Future optimization opportunities identified (with unknown performance impact) include:

  • switching from -02 to -0z, adding wasm-opt step
  • compress wasm text (testing showed brotli + z85 encoding to be largest byte reduction)
  • strip data that can be extrapolated from wcwidth

@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@35

commit: 79052b0

Copy link
Copy Markdown
Member

@dreyfus92 dreyfus92 left a comment

Choose a reason for hiding this comment

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

overall looks really good. since you're optimizing install size, are you planning on the near future to add a "no size regression test", cause rn there's nothing in the CI that asserts the package stays under a certain size. without that the size could quietly creep back up over time.

Comment thread tasks/build-npm.ts Outdated
Comment thread tasks/build-npm.ts
Comment thread tasks/build-npm.ts Outdated
natemoo-re added a commit that referenced this pull request May 24, 2026
Co-Authored-By: ghostdevv <ghostdevbusiness@gmail.com>
natemoo-re added a commit that referenced this pull request May 24, 2026
- replace sourceMap/declarationMap/target compiler options with skipSourceOutput: true
- add type: "module" to package config
- remove redundant files: ["esm"] (npm excludes lock files automatically, .npmignore handles the rest)

Co-Authored-By: ghostdevv <ghostdevbusiness@gmail.com>
natemoo-re added a commit that referenced this pull request May 24, 2026
Co-Authored-By: ghostdevv <47755378+ghostdevv@users.noreply.github.com>
@cowboyd
Copy link
Copy Markdown
Collaborator

cowboyd commented May 24, 2026

There are a couple of optimizations here; some of which I'm 100% cool with, the others I think we need to make sure we do intentionally.

Unalloyed Wins:

  • The linker changes to only export the functions we need and to gc/strip the rest. I don't see a downside to this.
  • same with the npm bundle changes

Needs consideration

  • switching from -02 to -0z is going to result in a smaller bundle size, but there will be a degradation of runtime performance. How much? I've no idea. We should add some benchmarks so that we can understand the tradeoffs
  • the compression of the wasm text is going to add a tiny bit of overhead to the startup time. Do we know how much it will be?
  • as for the wcwidth. That's a piece of the codebase we took from termbox2, so while I'm not opposed to the changes, but I don think we need to make sure we understand it.

Comment thread deno.json Outdated
@cowboyd
Copy link
Copy Markdown
Collaborator

cowboyd commented May 24, 2026

@natemoo-re

switching from -02 to -0z is going to result in a smaller bundle size, but there will be a degradation of runtime performance. How much? I've no idea. We should add some benchmarks so that we can understand the tradeoffs

Just so we don't block this work, can we merge all the other size optimizations and then consider these C options separately in the context of knowing how runtime perf is impacted?

@natemoo-re
Copy link
Copy Markdown
Member Author

natemoo-re commented May 24, 2026

switching from -02 to -0z is going to result in a smaller bundle size, but there will be a degradation of runtime performance. How much? I've no idea. We should add some benchmarks so that we can understand the tradeoffs

Just so we don't block this work, can we merge all the other size optimizations and then consider these C options separately in the context of knowing how runtime perf is impacted?

@cowboyd yep that sounds like the right path forward! happy to split those out with some benchmarks

Reverts three changes that need benchmarks before landing:
- -Oz / wasm-opt
- brotli+Z85 wasm compression
- wcwidth.c rewrite
@natemoo-re natemoo-re requested a review from cowboyd May 24, 2026 17:29
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