micro-ml is a tiny machine-learning and statistics library for JavaScript: 16
algorithms, zero runtime dependencies, 56KB gzipped. The core is Rust compiled to
WebAssembly. A year in, here's what I'd do the same and what I'd never do again.
The bundle-size trap
WASM is not free. A naive wasm-bindgen build shipped a 400KB .wasm blob before
I'd written a single algorithm. Most of it was panic-unwinding machinery and
formatting code I never called. Setting panic = "abort", stripping debug info,
and running wasm-opt -Oz got the binary down to something I wasn't embarrassed
to put in someone's frontend.
wasm-bindgen footguns
Passing a Float64Array across the JS/WASM boundary copies it. Do that in a hot
loop and you've built a library that's slower than the pure-JS version it was
supposed to replace. The fix was to expose a thin handle API: allocate once,
operate in WASM, read back once.
The real lesson: zero-deps is a hard sell
I assumed "16 algorithms, zero dependencies, 56KB" would sell itself. It didn't. JavaScript developers don't want a Rust toolchain in their build, and they're right not to. Shipping prebuilt artifacts, an honest size badge, and a copy-paste example that runs in the README did more for adoption than any benchmark.