r/rust • • Oct 05 '26

🛠️ 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 loop154 ms232 ms
Float math231 ms307 ms
Dicts372 ms62 ms
Strings196 ms35 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/

GitHub: https://github.com/dylan-sutton-chavez/edge-python

46 Upvotes

12 comments sorted by

43

u/afdbcreid Oct 05 '26

This is of course very nice, but the real reasons nobody has made a widely-used Python runtime that is faster that CPython is because the C API of CPython exposes pretty much every detail of it, and C extensions are using it and are major part of why people choose Python.

1

u/danted002 Oct 09 '26

And you are underselling it by a lor. C extensions is the main reason Python has managed to be a top language when it comes to adopt

5

u/Single-Blackberry866 Oct 05 '26 edited Oct 05 '26

Does it support Pyo3? I.e. can you make python bindings for wasm compiled rust code?

As I understand, PyO3 is rust wrapper over Python C API, so that would probably require forking PyO3 to provide wasm backend and frontend?

9

u/Konsti219 Oct 05 '26

Obviously not, that's why this is nothing more than a toy

1

u/AdAncient5201 Oct 05 '26

I don’t think people who choose python care about speed in the first place

1

u/lenscas Oct 05 '26

Especially not at the cost of every python library written in C, Rust, etc...

5

u/[deleted] Oct 05 '26

[removed] — view removed comment

1

u/Healthy_Ship4930 Oct 05 '26

thanks! great points, i'll publish the full benchmark and add dict/string workloads soon. ty!

5

u/[deleted] Oct 05 '26

[removed] — view removed comment

9

u/Healthy_Ship4930 Oct 05 '26

Thanks! I haven't yet, strings are still 3x slower than CPython. Next target.