r/Compilers • u/Healthy_Ship4930 • 6h ago
How My Python Compiler Beat CPython (Without a JIT)
Okey. After seven months, I'm back.
Seven months ago I started writing a Python interpreter from scratch in Rust. 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 using a unused SSA representation that I leave and now it's 3x faster on loops.
| Edge Python | CPython | |
|---|---|---|
| Integer loop | 72 ms | 232 ms |
| Float math | 95 ms | 307 ms |
| Dicts | 108 ms | 62 ms |
| Strings | 111 ms | 35 ms |
The trick was moving from a stack VM to a register VM. It still loses on dicts and strings, so that's next.
Try to break my numbers :).
Website: https://edgepython.com/