r/typescript • u/dupontcyborg • Mar 20 '26
numpy-ts is now 8-10x faster with WASM
I’ve been working on numpy-ts for the past ~5 months as a way to bring numerical computing to the JS/TS ecosystem. It became functionally complete a month ago, but I frequently heard concerns that it will never perform as well as NumPy’s BLAS and C backend.
So I’ve spent the past several weeks working on changing that. By writing numerical kernels in Zig, compiling them to WASM, and inlining them in TS source files, I’ve been able to speed up numpy-ts by 8-10x, and it’s now on average only 2.5x slower than native NumPy. It’s still early days and I’m confident that gap can go down. You can check out the benchmarks here.
The worst performers right now are FFT and complex linalg (around 15x slower than native) while other functions like integer matrix multiplication are 12x faster than native!
I decided on a microkernel architecture to keep numpy-ts completely tree-shakeable. This makes it super portable and keeps the library light. Even with the all kernels and no tree-shaking, it’s under 200kB gzipped.
This was written by a software engineer with AI assistance. Read my AI disclosure for more info.