Quick and dirty testing wizer against wasm binaries built with rust and ran using wazero runtime.
Spoiler: it works perfectly :)
wizer is a pre-initializer for Wasm - think wasm-opt.
This would allow you to do something resource intensive at build time, rather than runtime. For example, you could pre-initialize multiple regexes that are normally quite expensive.
This test verifies that wizer works with wasm artifacts produced by wazero.
There are two test cases:
wasm-regex and wasm-sleep
This test case has two wasm files - wasm-regex-regular.wasm and wasm-regex-init.wizer.wasm.
*regular*contains regex init code directly in the_start()func.*init.wizer*contains regex init code in theinit()func.
make run will show how long wazero run ... took to run both of the wasm files.
time isn't precise enough to give a definitive answer as to what's faster, so
need another more test that gives us a clearer picture.
In this case, *regular.wasm will sleep for 5s before printing "John Doe".
*init.wizer.wasm will sleep for 5s in the init() func and print "John Doe"
in the _start() func.
Same as with wasm-regex:
*regular*contains sleep code directly in the_start()func.*init.wizer*contains sleep code in theinit()func.
You should see that *init.wizer.wasm will take <1s to run while *regular.wasm will take >5s.
~/Code/streamdal/wasm-pre-init master* ◒
❯ make run
Testing wasm-regex-regular...
time wazero run -env NUM=123 build/wasm_regex_regular.wasm
Matched!
3.52 real 3.49 user 0.03 sys
Testing wasm-regex-init...
time wazero run -env NUM=123 build/wasm_regex_init.wizer.wasm
Matched!
3.48 real 3.46 user 0.02 sys
Testing wasm-sleep-regular...
time wazero run build/wasm_sleep_regular.wasm
Name: John Doe
5.07 real 0.06 user 0.01 sys
Testing wasm-sleep-init...
time wazero run build/wasm_sleep_init.wizer.wasm
Name: John Doe
0.07 real 0.06 user 0.01 sys- Install
wazeroCLI binary; installwizervia cargo. - Run
make build<- this will create .wasm artifacts in./build/* - Run
make run<- this will performtime wazero run ...on each one of the wasm files in the./builddir.