Python compiler in Rust that runs faster than CPython with a 160KB WASM

3 pointsposted 12 hours ago
by dylansuttonc

3 Comments

emanuele-em

10 hours ago

The fib benchmark is wild. I spent some time in the source. How are you handling back edges in loops in the single-pass SSA? You need to insert the phi before you've seen all the definitions, curious what the approach is there. Also how would you position this vs RustPython? They're going for full CPython compatibility (stdlib, pip, venv), whereas this looks like a small, fast, sandboxed runtime built for edge/WASM contexts. Very different bets. Is that the right way to read it? I had a similar project in mind for a while. Following this closely.

dylansuttonc

8 hours ago

Hi! Happy that you’re interested in the project and following it closely. I’m always open to seeing other people’s work as well.

While I use SSA, it’s not complete... my approach is pragmatic. For loops, each iteration generates new SSA versions of variables; at block end, they merge automatically, implicitly resolving phi nodes. This seemed simpler and safer than using pointers, and I’m applying a similar logic to objects.

Compared to RustPython, my focus is on binary size and speed rather than full CPython compatibility. My goal is to push Python to the frontend efficiently, for example, I plan to add an unsafe method to share a memory pool between JS and Python, allowing near-native DOM manipulation without serialization overhead.

Beyond parsing Python syntax (handled well by the lexer and parser), I aim to eventually support Pip and Rust’s Cargo libraries (first Cargo). I have a plan to compile C code while avoiding Python’s PyObject layout, enabling future library compatibility in this lightweight runtime.

Thanks! And happy to connect in the future :).