Live data from Hacker News

Python: The Optimization Ladder

cemrehancavdar.com

71–80 of 154 posts

Re: Python: The Optimization Ladder

#71
post #20

Significant AI smell in this write up. As a result, my current reflex is to immediately stop reading. Not judgement on the actual analysis and human effort which went in. It’s just that the other context is missing.

So much "is real". It is ok to check your grammar, but this is slopabetes inducing.

Re: Python: The Optimization Ladder

#73

Instead of just using a language that isn't dog slow, why not jump through these 5 different hoops? It's much easier!

Because for 99% of cases python is fast enough and it's fast as fuck to code. And for the 1% that aren't, you have 50 different flavors of making it faster. And the final of which is "slap pybind on a c module to do the hot path in C" which then lets you minimize the suffering of C into a single high value location. And the rest of the code still gets to be Python.

Re: Python: The Optimization Ladder

#74

Python is perfect as a "glue" language. "Inner Loops" that have to run efficiently is not where it shines, and I would write them in C or C++ and patch them with Python for access to the huge library base. This is the "two language problem" ( I would like to hear from people who extensively used Julia by the way, which claims to solve this problem, does it really ?)

I have used Julia for my main language for years. Yes, it really does solve the two language problem. It really is as fast as C and as expressive as Python.

It then gives you a bunch of new problems. First and foremost that you now work in a niche language with fewer packages and fewer people who can maintain the code. Then you get the huge JIT latency. And deployment issues. And lack of static tooling which Rust and Python have.

For me, as a research software engineer writing performance sensitive code, those tradeoffs are worth it. For most people, it probably isn’t. But if you’re the kind of person who cares about the Python optimization ladder, you should look into Julia. It’s how I got hooked.

Re: Python: The Optimization Ladder

#75
In practice the ladder has two rungs for me. Write it in Python with numpy/scipy doing the heavy lifting, and if that's not enough, rewrite the hot path in C. The middle steps always felt like they added complexity without fully solving the problem.

The JIT work kenjin4096 describes is really promising though. If the tracing JIT in 3.15 actually sticks, a lot of this ladder just goes away for common workloads.

Re: Python: The Optimization Ladder

#76
post #4

Earlier quoted context omitted.

While this is great, I expected faster CPython to eventually culminate into what YJIT for Ruby is. I'm not sure the current approaches they are trying will get the ecosystem there.

I implemented most of the tracing JIT frontend in Python 3.15, with help from Mark to clean up and fix my code. I also coordinated some of the community JIT optimizer effort in Python 3.15 (note: NOT the code generator/DSL/infra, that's Mark, Diego, Brandt and Savannah). So I think I'm able to answer this. I can't speak for everyone on the team, but I did try the lazy basic block versioning in YJIT in a fork of CPyth…

Thank you for your contributions to the Python ecosystem. It definitely is inspiring to see Python, the language to which I owe my career and interest in tech, grow into a performant language year by year. This would not have been possible without individuals like you.

Re: Python: The Optimization Ladder

#77
post #44

Missing: write static python and transpile to rust pyO3 which is at the top of the ladder. Some nuance: try transpiling to a garbage collected rust like language with fast compilation until you have millions of users. Also use a combination of neural and deterministic methods to transpile depending on the complexity.

> a garbage collected rust like language with fast compilation I don't know what languages you might have in mind. "Rust-like" in what sense?

It's not a popular thing to say on social media.

V-lang is the one I'm tinkering with. It's like rust in terms of pattern matching as an expression, sum types, ?T instead of exceptions.

Like golang, it has shorter compile times.

I try to keep my argument abstract (that you need to lower python to something intermediate before rust) for that reason.

Re: Python: The Optimization Ladder

#78
post #44

Earlier quoted context omitted.

> a garbage collected rust like language with fast compilation I don't know what languages you might have in mind. "Rust-like" in what sense?

It's not a popular thing to say on social media. V-lang is the one I'm tinkering with. It's like rust in terms of pattern matching as an expression, sum types, ?T instead of exceptions. Like golang, it has shorter compile times. I try to keep my argument abstract (that you need to lower python to something intermediate before rust) for that reason.

Here is a python AST parser written in V. It's targeting a dialect that's mostly compatible with a static subset of python3, but will break compatibility where necessary. In this case pattern matching, possibly elsewhere.

https://github.com/py2many/v-ast

Re: Python: The Optimization Ladder

#79
post #38

Missing: write static python and transpile to rust pyO3 which is at the top of the ladder. Some nuance: try transpiling to a garbage collected rust like language with fast compilation until you have millions of users. Also use a combination of neural and deterministic methods to transpile depending on the complexity.

One thing with python is that usually I will use one of the many c based libraries to get reasonable speed and well thought out abstractions from the start. I architect around numpy, scipy, shapely, pandas/polars or whatever. So my code runs at reasonable speed from the start. But transpiling to rust then effectively means a complete redesign of the code, data structures, algorithms etc. And I have seen the AI tools…

Cython and all the libs you mention use the c-api, which is the #1 thing python needs to lose to be competitive.

I wish someone writes a stdlib without using it. My attempt from a few months ago in a repo under the py2many org.

Post reply on HN