Comment by snovymgodym

16 hours ago

It clearly isn't hurting Python's popularity, but man the performance of the reference implementation is embarrassing.

V8 made JavaScript fast in 2008, soon that will be 20 years ago.

Perhaps I live in a bubble, but so much of the production Python code I see is fully type-hinted and makes used of an aggressive linter & type checker to the point where it might as well be written in Go/C#/Java/TypeScript so that it can actually take advantage of the performance gains instead of being loaded into a runtime that turns everything into heap-allocated PyObject pointers.

I work in Python every day and think about this a lot - people really don't seem worried about its performance. Sure people want it to be faster, but I don't see very many people changing their language choice for a faster language, despite Python being a lot slower than most alternatives.

If I think about where I see python being used though, this kind of makes sense, the two big use cases are:

- Web APIs and backends, where for the most part either the network or the database is the bottleneck

- Data science work, where for the most part, work exists in libraries like polars, pytorch etc that ship the main work out to other languages.

So from that perspective, although we'd all like python do be faster, it's speed isn't the bottleneck in the use cases where its popular (that's probably also the reason why we don't see Python getting used in other speed critical places).

That's a really different story to JavaScript, which doesn't have a handy CFFI or otherwise you can just reach out to. There are a lot of cases where JavaScript speed improving would speed up the reactivity of a web app, even now.

I'm not arguing against a faster CPython - I'd love one! But I think there's a clear reason why it hasn't been prioritised historically in the way JavaScript's performance has.

This is exactly how I write my Python. I'm currently debating between going in deep and transitioning to either TypeScript or Rust. Go's object system and error handling is too weak. Java is too verbose, but I have a soft spot for it.

If you want V8 like optimizations, you have to introduce a strict mode.

Python interpreter is known to leak its implementation (__class_ modification after creation, monkey patching with __getattr__, sys._getframe, eval/exec, deterministic call to __del__, no proper python API for libraries, etc.)

You have to plug all of those holes before having a chance to get a decent JIT. Otherwise it will be just another JIT attempt, like Psyco, Unladen Swallow, Pyston.

  • Python is not uniquely dynamic to a degree that would prevent an efficient implementation.

    V8 predates strict mode, and handles all the exec/eval, monkey patching and object system abuse you can do in JavaScript just fine. Common Lisp is one of the most dynamic languages in the world and allows you to do ridiculous things in terms of meta-programming and essentially building domain-specific languages into your program, yet it too manages to have ahead-of-time compiled implementations that are very performant. Also PyPy exists.

    There are definitely some technical aspects that make it hard to make Python fast, but they are not insurmountable. The reason CPython is slow today is simply because performance has not historically been prioritized by its developers.