r/Compilers • u/Healthy_Ship4930 • Oct 05 '26
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/
5
u/schungx Oct 05 '26
Did switching to SSA from stack cause the huge speed difference in loops? Or is it together with some other optimizations?
I'm at a loss to explain such huge speed difference, like 9x. Even though SSA reduced stack pushed and pops, the value still has to sit somewhere, so either the stack or the VM's own stack... Either way it should not see 10x perf boost.
Did your bytecodes start off with loads of push-pop pairs that you didn't eliminate?
6
u/yuehuang Oct 05 '26
Good job.
One benchmark I would like to see is reading from a large CSV, 1-2gb of large intergers, then sorting it. (repeat numbers allowed)
While the sort operation itself isn't important, it would shows that random access is fast.
5
u/[deleted] Oct 05 '26
Is this the same product that you'd previously said was 10,000 times faster than CPython on recursive Fibonacci? (That was due to use or memoisation so was an unfair comparison.)
This set of figures is more reasonable. CPython is famously slow, so beating it on actual bytecode instructions is viable.
The Dicts and Strings tests will be more about internal support, which will be highly optimised internally - less of the overhead will be spent on instruction and type dispatch.
I couldn't find those four benchmarks within your links, not as discrete files. So I couldn't do my own tests.
1
u/MetalInMyVeins111 Oct 06 '26
How much of it is AI?
3
u/Slow-Ad9462 Oct 05 '26
Just don’t call it Python compiler, and than it’s an interesting project. Also, there’s no reason to compare with CPython. You compile a static typed subset of Python language, be explicit and clear. Otherwise it’s yet another “python compiler” we’ve seen over the years, and none of them got traction