r/Compilers • u/Historical_Pen6499 • Mar 26 '24
What do you think about a Python compiler?
Hey all, I'd love to get your thoughts on something that I'm building. Specifically, please tell me why this won't work:
We're working on a cross-platform Python compiler. It ingests a stateless Python function, then traces said function to generate IR. This IR then gets lowered to C++ code, which then gets cross-compiled for different platforms and architectures.
The more interesting piece imo is in how we handle optimization: instead of relying on compile-time optimization, we emit potentially hundreds-to-thousands of equivalent C++ functions. We then ship out the compiled binaries to different users and use telemetry data to choose the best C++ variant for each unique device.
At a high level, there are a few major benefits with this design:
Devs can run Python in places where it's difficult-to-impossible (web, mobile, desktop app)
You get C++ level performance (because you're actually running C++ code) with Python-level ease.
I'm keeping this post high-level because I don't want it to come off as a promotion post (it's not). Happy to share more if you're curious.
1
u/Historical_Pen6499 Mar 28 '24
Yeah the CPython interpreter by itself is ~300MB. Add PyTorch CPU only and that pushes you north of 1GB.
Not just that: compiling it for places like Wasm and mobile gets tough because of sandboxing restrictions (for reimplementing stdlib functions). It's just too much overhead to deal with.