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

What My Project Does

Edge Python is a Python 3.13 compiler written in Rust — hand-written lexer, single-pass SSA parser, and an adaptive VM with inline caching and template memoization. It runs fib(45) in 11ms where CPython takes nearly 2 minutes.

def fib(n):
    if n < 2: return n
    return fib(n-1) + fib(n-2)
print(fib(45))
Runtime fib(45)
CPython 3.13 1m 56s
Edge Python 0.011s

The parser already covers ~97% of Python 3.13 syntax. The VM implements arithmetic, control flow, functions, closures, collections, f-strings, and 13 builtins including a configurable sandbox (recursion, ops, heap limits).

I recently replaced the DFA lexer (Logos) with a hand-written scanner to shrink the WASM binary. Next step is getting the WASM build under 60KB so I can ship a Python editor that runs entirely in the browser.

git clone https://github.com/dylan-sutton-chavez/edge-python
cd compiler/
cargo build --release
./target/release/edge script.py

The project isn’t finished, there are still VM stubs to implement and optimizations to land. But I’d love early feedback on the architecture, the bytecode design, or anything else that catches your eye.

Target Audience

Anyone interested in compiler design, language runtimes, or Rust for systems work. Not production-ready, it’s a real project with real benchmarks, but still missing features (classes, exceptions, imports at runtime). I’m building it to learn and to eventually ship a lightweight Python runtime for constrained environments (WASM, embedded).

Comparison

  • CPython: Full interpreter, ~50MB installed, complete stdlib. Edge Python targets a ~60KB WASM binary with no stdlib, just the core language, fast.

  • RustPython: Full Python 3 in Rust, aims for CPython compatibility. Edge Python trades completeness for size and speed, SSA bytecode, inline caching, no AST intermediate.

  • MicroPython: Targets microcontrollers, ~256KB flash. Edge Python targets WASM-first with an adaptive VM that specializes hot paths at runtime.

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

Thanks for reading, happy to answer any questions :).

6 Likes

What’s in the 3% that’s not covered? Anything we really can’t live without?

1 Like

Well that’s a breath of fresh air these days! Very cool.

Those are some pretty big features. Do you anticipate any obstacles implementing them with this design?

I can understand why the no-stdlib approach makes sense for the initial design, but of course there’s a lot of important stuff in there. Beyond imports, do you plan to add support for extension modules? In my opinion that’s probably the biggest challenge after implementing the language, but if you support extensions and imports you don’t need to implement the stdlib yourself.

4 Likes

I could be wrong, but the 97% is just the parser, and so significantly more isn’t implemented in the runtime (i.e. classes and exceptions, which some people would claim are important features of Python)

3 Likes

Thanks. This project sounds cool, and not trying to compile every possible piece of dynamic code is a reasonable compromise, when it’s such early days for any Python compiler. It’s not necessarily a bad thing at all either (especially parking things like setattr, match statements and The Walrus for later).

I’d just like to know what exactly has been left out (or is yet to be supported, say), before I get too excited.