Here's the source code I used
import { readSync } from "node:fs";
const buffer = new Uint8Array(32);
readSync(0, buffer, 0, buffer.length );
process.stdout.write(buffer);
Here's the compilation command
SCRIPTC_NO_CACHE=1 SCRIPTC_CC=zigcc SCRIPTC_TARGET=wasm32-wasi bun x scriptc build hello.ts --keep-c --optimization release -o hello.wasm >/dev/null
Now, that spits out a 1.8 MiB WASM binary.
However, if I then do wasm2wat then wat2wasm starting with that same hello.wasm file, I get a 565.3 KiB WAT file and then a 53.1 KiB WASM file.
wabt-1.0.41/bin/wasm2wat hello.wasm -o hello.wat
wabt-1.0.41/bin/wat2wasm hello.wat -o hello1.wasm
Using wasm-opt directly on the hello.wasm file I get down to 46.9 KiB
wasm-opt hello.wasm -Os --strip-debug --vacuum -o hello2.wasm
Two questions arise for me:
- How to determine if QuickJS NG is embedded in the resulting WASM binary?
- How to optimize the WASM binary output so that is roughly matches the output of
wasm-opt?
Here's the source code I used
Here's the compilation command
SCRIPTC_NO_CACHE=1 SCRIPTC_CC=zigcc SCRIPTC_TARGET=wasm32-wasi bun x scriptc build hello.ts --keep-c --optimization release -o hello.wasm >/dev/nullNow, that spits out a 1.8 MiB WASM binary.
However, if I then do
wasm2watthenwat2wasmstarting with that samehello.wasmfile, I get a 565.3 KiB WAT file and then a 53.1 KiB WASM file.Using
wasm-optdirectly on thehello.wasmfile I get down to 46.9 KiBTwo questions arise for me:
wasm-opt?