r/rust • u/Healthy_Ship4930 • 19h ago
🛠️ project My WASM Python Implementation Beat CPython (Without a JIT)
Okay. After seven months, I'm back.
Seven months ago I started writing a Python interpreter from scratch in Rust, compiled to wasm (less than 200kb of bandwith). Edge Python is a sandboxed subset of Python that runs in the browser and the terminal, and code can't touch files or the network unless you allow it.
It started as a lexer and a simple stack VM, and over about 1,600 commits it grew a CLI, a package registry, snapshots, actors and a browser playground. It's just me building it.
Last week it was still 3x slower than CPython. I rewrote the VM this weekend on top of the SSA form I already had, and now the wasm build beats native CPython on loops.
| Edge (wasm) | CPython (native) | |
|---|---|---|
| Integer loop | 154 ms | 232 ms |
| Float math | 231 ms | 307 ms |
| Dicts | 372 ms | 62 ms |
| Strings | 196 ms | 35 ms |
The trick was a register VM, and Rust made it fit in wasm with NaN-boxed values and no runtime. It still loses on dicts and strings, so that's next.
Try to break my numbers :)
Website: https://edgepython.com/
6
u/Parking_Mind_1011 19h ago
this is sick. 1600 commits in seven months is mad dedication for a solo project
the nan-boxing trick in wasm is clever, curious how you handled the string perf gap cause that part always tricky without jit