247 points · by Radim · 4y ago · 228 comments
This cements the CPython team as sort of a known "don't waste your time there" in PL research communities, distancing themselves from the people most likely and willing to help maintain their runtime.
This is by a core python dev who is currently employed by Microsoft to enact this plan.
EDIT: I should caveat "doesn't actually break anything" with "although it does require you to install build dependencies because you have to compile the package from source instead of using a prebuilt wheel". I don't think this changes the substance of my comment but best to be precise.
You have to be prepared to factor out the key parts of the code into faster languages like C++ with bindings, if necessary. Or you can virtually do this, e.g. learn more about the standard library, make sure you are choosing things that actually are implemented natively underneath instead of in pure Python, etc.
And sometimes, you find that the cause of a slowdown is far more fundamental (e.g. the entire algorithm is not good, and you see huge gains by redoing it, even if everything is still interpreted code).
Yes. However, this is exactly where Python (imho) shines. You get a convenient interpreted language which seemlessly interacts with highly optimized native libraries like numpy, scipy, xarray,... and of course ML frameworks (where impact of base language speed is negligable compared to the time it takes to train a model).
Agreed. Equally the faster the interpreted language, the less you need to offload, because baseline speed is good enough.
Faster is rarely a bad thing.
Stripe had the innovative idea of compiling ahead of time parts of the code (taking advantage of type annotations). I think this is a very interesting approach that may make usage of faster language unnecessary in a certain amount of cases.
The generated code is pretty hilarious since you end up with HashMaps and dynamic dispatch everywhere.
Much better gains can be made by simply not using Python.
Sure the language is great, and it is very easy to write extensions in C, however as the performance pressure keeps increasing, in the end it is a C application where Tcl was reduced to a configuration/orchestration language.
Since then, if it doesn't have a JIT or AOT compiler in the box I am not interested, unless I am obliged to do so by higher levels.
I've worked on a system like that where it was just nothing to optimize really (anymore). It was just lots of code and there was no hot path to optimize.
The single example I typically give is that in Python you can inspect stack frames after they've exited! This has concrete implications on your VM design.
Another example is that the multiple dispatch protocol for binary operations (such as addition) is sufficiently complicated that you generally cannot encode it into your compiler. We have been able to have a simplified version of that by building a tracing JIT for C, which is able to understand the dispatch protocol, but it is not always applicable.
Source: I've been working on Python optimization for several years as part of the Pyston project.
How about an implementation of python that doesn't let you do fancy things like that that are not needed in production?
People have tried, pypy started with that goal before it became clear it wasn't practical.
From what I’ve seen last time I heard about graal python is that it is seldom faster than the pypy approach (AST-based vs tracing JIT), even though in case of TruffleRuby and TruffleJS it is insanely fast compared to the maturity of the projects.
Is your mentioned example of stack frame inspection make it map much worse to Java primitives (which happens behind the scenes of the truffle languages)?
How does that work and what is it used for?
https://markmail.org/message/dp56i26zhpf4fehb#query:+page:1+...
Also I think Python’s truthy/falsey semantics make it dangerously close to being weakly typed.
How Python was Shaped by leaky Internals(2016):
https://www.youtube.com/watch?v=qCGofLIzX6g
See also this HN post (Attempts to make Python fast):
Then release a new 'fast' module API, and all the performance critical modules will soon move over.
So I stipulate that if the runtime becomes faster, those gains won't be visible to large swathes of code because python libraries do lots of weird things under the hood.
https://markmail.org/message/dp56i26zhpf4fehb#query:+page:1+...
Unfortunately, there is no Python subset people can stick to as such. But you can use e.g. TransCrypt to compile Python to JavaScript; the docs tell you about an efficient subset. It should be possible to build an efficient Python JIT for such a subset (and you sort of have one already through TransCrypt and JS)
a become: b
It is a myth that only Python enjoys such dynamic capabilities, it happens to be a convenient excuse.And the fact that there are languages as dynamic as Python is not as important as how it is implemented through the language; Lua is about as dynamic as Python, but with effects that are much more local in general. IIRC Mike Pall (of LuaJIT fame) said that Lua was almost optimal for JITting, JS is sort-of-ok if you ignore some things, but Python is beyond hope -- and I tend to think he knows what he's talking about, given that his hobby, one-man-show LuaJIT handily beat all well-funded-with-tens-of-employees JS engines for a very long time (maybe still does).
I wonder how good the SmallTalk JITs really are by today's standards, in the presence of e.g. "become:". The fact that's it is there, and supported, doesn't mean it's in common use, or supported efficiently -- just like JavaScript's "with".
Where have you seen it used as an example in that way?
The second is the inspect module that builds on that, allowing you to get the stack frames, inspect function signatures etc.
The third is trackbacks, which need the stack and themselves are introspectable.
The fourth is metaclasses (making dynamic classes at runtime).
These are heavily used in Python, and are optimisation barriers. For example PyPy (Python with a JIT) disables optimisations when “inspect” is imported or used anywhere in the call stack.
https://techspot.zzzeek.org/2015/02/15/asynchronous-python-a...
I'm not sure I'd use the word "frequently" here, but I could just have a different experience. Most projects are boring CRUD stuff, and something else have always been the bottleneck before the actual language itself, most of the times different types of I/O but also just poor choice of algorithms/data structures. I don't think I've ever actually came across a situation where the language itself was the bottleneck of the performance, but I don't normally work super close to performance-sensitive projects as I said, mostly common web tasks.
Especially with regards to the environment.
You may laugh all you want, the ever expanding internet should become way more resource friendly.
I don't think this really exists today partly because of the comment you replied to.
Rails, Django and Laravel are massively optimized for developer productivity to build web applications and use languages that have been around long enough where the community has created widely successful and popular libraries to implement mostly common features for things aren't included by default. Libraries that go beyond 1 developer maintaining them in their free time.
If you can build a web app and host it for $40 a month on a single VPS that can sustain tens of thousands of users and you can make a million dollars a year as a solo developer what incentive is there to switch to a faster language? Your secret weapon here is being able to build things quickly and not have to single handily develop a bunch of common lower level libraries just to build the app features you want.
For when you need to scale out we have Kubernetes which generally works the same to scale out most types of web apps. It seriously (honestly) doesn't matter if your hosting bill is $10,000 / month instead of $3,000 / month when you have a team of 8 developers ($240,000 / month) on payroll and your web app is happily returning p99 responses in under 150ms while your business profits tens of millions of dollars a year. What does matter is how fast you can build new features while maintaining your app and finding qualified developers.
Because "developer hapiness" and "speed of development" are also tradeoffs with other languages...
In fact, if you're late to the market because you used some speedier language, it's often as good as not launching at all...
Obviously: if speed of development and speed of program were non-problematically compatible, everybody would always go for both (why lose speed, if you can have the same development experience)? But speed requires several things, like more careful algorithms and program design, custom solutions instead of one-size-fits-all libraries and frameworks, more care regarding memory usage, time spend for optimization, use of a statically typed language as opposed to a higher level scripting one, slower build/jit times (as opposed to interpreter), and so on...
Horizontal scaling is going to be an issue eventually, no matter the language. You can serve tens of thousands of people off a single django server. Unless you're going to hit a growth limit at specifically 3-5x what a single vertically scaled django server can do, or you know for a fact that webserver compute is going to be the bottleneck, development speed rules all else.
I’ve written a lot of python outside of the web space and a lot of JavaScript in the web space and I can’t think of a time I wish I was writing in python.
Modern JavaScript has a really expressive syntax without the runtime performance hit.
I'd also argue that syntax-wise they are virtually the same language and not worth really comparing. It's not like either is ML.
If the latter can't use numpy or would be slowed down by it, that's a fair comparison, but it looks like they are just at different stages of optimization.
My work would become an order of magnitude easier if I did not have to use multiprocessing to get parallelism across shared memory.
If some fork of python that has no GIL becomes popular, another python 3 situation could emerge with the community splitting.
This "reference implementation should be simple and easy to read" is the dumbest part of python, unnecessarily holding it back imo.
facts
1. this is a thread about cpython. jax is as relevant to users of cpython as CUDA or OpenCL or whatever. jax cannot do absolutely anything with e.g. django.
2. for all intents and purposes all numerical code always runs in a lower-level implementation (C++, CUDA, XLA, whatever). so from that perspective, jax is just a convenient way to get from numerical python (i.e., loops and muls and adds) to kernels.
Yes, tight numerical loops are going to benefit from JIT compilation, this isn't surprising. It's also not a very typical workload for either Python or Javascript.
Math-heavy benchmarks are not really representative of what Python is used for. They benefit from things like SIMD and aggressive inlining and fine-grained control over memory layout, etc. If you need that with Python, you can use something like NumPy or implement the hot path with a native language.
At the end of the day code is optimized portable machine state for a given task. The syntax is arbitrary.
More cynically, Python, Ruby, have hurt as many projects as they’ve helped. Their slowness has wasted countless cycles. Now we can quantify it rather than be lost to the hype we felt learning this “magic” to begin with.
With respect, Guido; this feels like a vanity project for a bored retiree, soaking up human effort and real agency. Perhaps you should have simply stayed retired and learn a new hobby.
About 14% faster than 3.10.
Still at only ~80% performance compared to python 2.7
It seems absurd to not mention the API upstreamed by the Pyjion attempt, especially in the context of optimizing bytecode / touching into machine code?
I dunno, maybe I'm just perturbed by the amount of duplicated effort on this singular topic
The Faster CPython Project is already yielding some exciting results: this version of CPython 3.11 is ~ 19% faster on the geometric mean of the PyPerformance benchmarks, compared to 3.10.0.
https://pythoninsider.blogspot.com/2022/01/python-3102-3910-...
So this is definitely not languishing as they are getting these changes directly into main for Python 3.11
All times in seconds (lower is better)
benchmark Node.js Python 3 Py takes x times longer
==================================================================
regex-redux 5.06 1.34 ** Py3 is faster (PCRE C)
pidigits 1.14 1.16 0.02
reverse-complement 2.59 6.62 2.56
k-nucleotide 15.84 46.31 2.92
binary-trees 7.13 44.70 6.27
fasta 1.91 36.90 19.3
fannkuch-redux 11.31 341.45 30.19 (wut?)
mandelbrot 4.04 177.35 43.9 (srsly?)
n-body 8.42 541.34 64.3 (no numpy fortran cheat?)
spectral-norm 1.67 112.97 67.65 (Python for Science[TM])
(If Python is allowed to call fast C code (PCRE) for regex-redux, I don't see why Python shouldn't be allowed to call fast Fortran BLAS/etc for n-body, but rules are rules, I guess. V8 doesn't cheat at spectral-norm, it's 100% legit JS.)Both ecosystems have billions invested by corporations worth trillions; bottomless money exists to make Python faster. So why isn't Python faster?
V8's tactics include dynamically watching which loops/calls get run more than (say) 10,000 times and then speculatively generating[2] native machine instructions on the assumption the types don't change ("yep, foo(a,b) is only called with a and b both float64, generate greased x86-64 fastpath"), but gracefully falling back if the types later do change ("our greased x86-64 'foo(float64,float64)' routine will be passed a string! Fall back to slowpath! Fall back!"). Why doesn't Python do this? Is it because Google recruited the only genius unobtainium experts who could write such a thing? Google is a massive Python user, too.
[1] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
[2] https://ponyfoo.com/articles/an-introduction-to-speculative-...
EDIT: HN commenter Jasper_ perhaps has the answer in another post[3]: "The current CPython maintainers believe that a JIT would be far too much complexity to maintain, and would drive away new contributors. I don't agree with their analysis; I would argue the bigger thing driving new contributors away is them actively doing so. People show up all the time with basic patches for things other language runtimes have been doing for 20+ years and get roasted alive for daring to suggest something as arcane as method dispatch caches. The horror!"
The regex and arbitrary precision number libraries were allowed for regex-redux and pidigits because some language implementations wrapped those libraries rather than implement their own thing.
That sounds amazing but doesn't square with my experiences as a technical PM/PO. We might have different definitions of "fast", but generally speed-optimized code is very different than prototype code (enough so that prototype "correctness" is non-transferable), more difficult to create in comparison to the prototype, and is often rewritten in a different language (Rust, C, assembly). For example, you're never going to write anything other than a toy video encoder in Python.
"At some point, you end up with one little piece of your system, as a whole, where you end up spending all your time. If you write that just as a sort of simple-minded Python loop, at some point you will see that that is the bottleneck in your system. It is usually much more effective to take that one piece and replace that one function or module with a little bit of code you wrote in C or C++ rather than rewriting your entire system in a faster language, because for most of what you're doing, the speed of the language is irrelevant."