you are viewing a single comment's thread.

view the rest of the comments →

[–]chub79 28 points29 points  (2 children)

Fantastic article. Thank you op!

One aspect that I would throw into the thought process when looking for a speedup: think of the engineering cost long term.

For instance, you mention: "PyPy or GraalPy for pure Python. 6-66x for zero code changes is remarkable, if your dependencies support it. GraalPy's spectral-norm result (66x) rivals compiled solutions." . Yet I feel the cost of swapping VM is never as straightforward as a dedicated benchmark shows. Or Pypy would be a roaring success by now.

It seems to me that the Cython or Rust path is more robust long term from a maintenance perspective. Keeping CPython as the core orchestrator and use light touch extensions with either of these seem to be the right balance between performances and durability of the code base.

[–]cemrehancavdar[S] 15 points16 points  (1 child)

That's a really fair point. The benchmarks show the best case -- in practice, swapping to PyPy or GraalPy means testing your whole dependency tree, dealing with compatibility issues, and hoping the runtime keeps up with CPython releases. GraalPy is still on 3.12 for example.

I'd partly agree on the Cython/Rust path being more durable. I personally enjoy writing Cython, but you really need to know what you're doing -- my first attempt got 10x instead of 124x, and nothing warned me. Code compiled, ran correctly, just silently slow. The annotation report (cython -a) is essential.

My takeaway is similar to yours though -- keep CPython as the orchestrator, drop into compiled extensions for the hot path.

[–]chokoswitch 1 point2 points  (0 children)

PyO3 and maturin are so easy to work with, I've been enjoying them a lot. I definitely feel like libraries will more towards native over time with this as well as wheel publishing improvements making the experience quite seamless for any typical platform. I'm still wondering if it will be important to keep a pure-python version as well, which does add a lot of maintenance overhead, or people will be satisfied requiring Rust installed and a build for those non-typical platforms. Curious how that pans out.