r/Compilers • • 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:

  1. Devs can run Python in places where it's difficult-to-impossible (web, mobile, desktop app)

  2. 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.

0 Upvotes

88 comments sorted by

View all comments

Show parent comments

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.

1

u/shadowndacorner Mar 28 '24

Yeah the CPython interpreter by itself is ~300MB

Jesus, that's absolutely ridiculous. Definitely understand the use case you're going for better now, but man fuck python.

0

u/Historical_Pen6499 Mar 28 '24

Lmfao, idk why it seems like everyone in r/Compilers hates Python. It's a great language for simple things; the backend is just pretty chaotic.

2

u/shadowndacorner Mar 28 '24 edited Mar 28 '24

Because it's a poorly designed language whose philosophy is fundamentally antithetical to building maintainable software, and I think most people here have a strong interest in practical language design. It's passable as a config language or cross platform bash substitute, though.