Skip to content

Shorten the generated bindings in the bundle - #160

Merged
ceifa merged 1 commit into
new-apis-2from
perf/reduce-bundle-size
Nov 20, 2026
Merged

ceifa merged 1 commit into
new-apis-2from
perf/reduce-bundle-size

Conversation

@ceifa

@ceifa ceifa commented Nov 20, 2026

Copy link
Copy Markdown
Owner

What

The constructor utils/create-bindings.js generates spelled out this.exported( 147 times and this.wrapWithStringArguments( 37 times. A minifier cannot shorten a method name, so each one landed in the bundle in full. The constructor now builds the bindings through two locals, raw and withStrings, which it can.

The bindings are still named stores in the constructor, so the instance layout is unchanged.

before after
dist/index.js 113,383 B 110,677 B
gzipped 35,145 B 35,055 B
dist/glue.wasm 194,124 B 194,124 B

glue.wasm and both glues are byte for byte the same. LuaRuntime.load() measures the same before and after (1.78 ms median, interleaved A/B).

The README size table was stale (108 + 194) and now carries the measured numbers.

What was tried and left out

This is about all there is without trading something away. Measured and dropped:

  • Build flags: -flto, a single translation unit through onelua.c, -Os, -O2, extra Binaryen passes, EVAL_CTORS and TEXTDECODER=2 all tie with the current -Oz or come out larger.
  • --closure 1 on the glue: 79 kB to 43 kB out of emcc, but it renames FS methods (mount, mkdirTree, lookupPath, syncfs, ...), which breaks the public emscripten.FS.
  • libc's strtod: about 14.6 kB of the wasm, since musl's parser pulls in 128 bit soft-float. Dropping it means a float parser of our own.
  • private to #private: the minifier does shorten #names, for an estimated 4 kB, but it is a refactor of about 110 members on hot paths.

Testing

npm test (486 passing) and npm run lint:nofix.

The generated constructor spelled out this.exported( 147 times and this.wrapWithStringArguments( 37 times, and a minifier has to leave a method name alone. Two locals in the constructor take their place, so the named stores stay as they were and dist/index.js goes from 113.4 kB to 110.7 kB.

The README size table was stale (108 + 194) and now carries the measured numbers.
@ceifa
ceifa changed the base branch from main to new-apis-2 November 20, 2026 01:52
@ceifa
ceifa merged commit 0cd201a into new-apis-2 Nov 20, 2026
1 check failed
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.

1 participant