News for hackers. Stuff that matters.
Re:Python 3.11.0 final is now available by iruoy on Tuesday October 25, 2022 @05:30AM (#33328240)
Pypy and Pyston are still quite a bit faster than CPython, but this is a huge improvement in one release.

https://www.phoronix.com/review/python311-pyston-pypy

Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @05:40AM (#33328307)
Someday it will get a proper JIT I guess.
Re:Python 3.11.0 final is now available by nigma1337 on Tuesday October 25, 2022 @06:24AM (#33328584)
Planned for 3.12

> Simple "JIT" compiler for small regions. Compile small regions of specialized code, using a relatively simple, fast compiler.

https://github.com/markshannon/faster-cpython/blob/master/pl...

Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @07:08AM (#33328921)
I guess better than nothing then.
Re:Python 3.11.0 final is now available by driscoll42 on Tuesday October 25, 2022 @08:27AM (#33329580)
When you're dealing with one of the most popular languages in the world and the cost of getting it wrong and breaking things is astronomical, being risk adverse and starting small seems like the way to go.
Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @08:30AM (#33329611)
Doesn't seem to hinder JavaScript runtimes.
Re:Python 3.11.0 final is now available by Sol- on Tuesday October 25, 2022 @08:55AM (#33329834)
Hasn't Microsoft experimented with disabling the JIT for security reasons?[1] Doesn't have much relevance for Python at the moment, but I'm just mentioning it to underline that a modern JIT can be very complex thing and keeping it simple for 3.11 seems like a very reasonable requirement.

[1] Random google result as source: https://www.cyclonis.com/microsoft-edge-tests-disabling-java...

Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @09:28AM (#33330193)
That isn't what is being discussed here, every JIT has a potential for eventually generating code patterns susceptible of exploits.
Re:Python 3.11.0 final is now available by acdha on Tuesday October 25, 2022 @09:19AM (#33330095)
JavaScript has multiple companies with valuations measured in billions of USD competing. Optimizing JavaScript is just as hard but they can throw massive development teams at the problem. Python isn’t without resources but the level of scale is dramatically different.
Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @09:29AM (#33330207)
Because those investing into machine learning frameworks in Python rather spend their resources rewriting their libraries in C, C++ and Fortran while calling it "Python".
Re:Python 3.11.0 final is now available by acdha on Tuesday October 25, 2022 @10:03AM (#33330592)
Sure, my point was just that the number of corporate investment in the core Python language is smaller. Investing in an ML framework isn’t a bad thing but it doesn’t support anyone working on the core language the way Google, Apple, Microsoft, Samsung, etc. contribute directly to Chromium/WebKit development.
Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @12:43PM (#33333010)
Some of those companies overlap both ecosystems.
Re:Python 3.11.0 final is now available by wheelerof4te on Tuesday October 25, 2022 @05:48PM (#33336600)
Python's ease of calling C libraries is both the blessing and a curse.

My opinion is that it's mostly a curse, since you are hampering the language's evolution and growth for a mere temporary benefit.

Not to mention the horror of distributing compiled libraries, which is one of the biggest reasons why packaging in Python is still such a nightmare.

Making CPython faster by getting rid of the GIL will do wonders for this language and it's community. It will make it much more portable, too. Think of Java-level portability, but in a much nicer package.

Re:Python 3.11.0 final is now available by dragonwriter on Tuesday October 25, 2022 @12:11PM (#33332540)
> JavaScript has multiple companies with valuations measured in billions of USD competing.

A couple of them have valuations in the trillions of USD, actually.

Re:Python 3.11.0 final is now available by acdha on Tuesday October 25, 2022 @12:26PM (#33332759)
Yeah, I thought about that when I was writing that but didn’t want to get into debates about what fraction of those resources they put into web stuff. Even if you ignore the big ones however, Mozilla is just web stuff and they’re still much bigger than the core Python team.

(Mozilla does support a ton of OSS, too, so read that as everyone else needing to step up rather than an attack on them)

Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @12:44PM (#33333031)
Google does Tensorflow and V8.
Re:Python 3.11.0 final is now available by acdha on Tuesday October 25, 2022 @03:30PM (#33335066)
Exactly: V8 benefits almost everyone using JavaScript, TF doesn’t benefit anyone not doing ML with that stack.

All I’m saying is that asking why JS performs faster than Python in some cases is less about the languages and more what you could do with hundreds of engineers working for years. If the stars had aligned differently and that effort had gone into Python (or Ruby, etc.) I’d expect a similar delta.

Re:Python 3.11.0 final is now available by chubot on Tuesday October 25, 2022 @09:53AM (#33330473)
JavaScript doesn’t have a C API, that makes all the difference
Re:Python 3.11.0 final is now available by brrrrrm on Tuesday October 25, 2022 @11:52AM (#33332261)
what about NAPI? Or deno/buns JITed api?

I’ve heard this “no C API” thing echoed by a couple people and it’s baffling. Do folks really think three major JS engines all written in C++ wouldn’t have an interface to interact with C?

Re:Python 3.11.0 final is now available by chubot on Tuesday October 25, 2022 @12:06PM (#33332466)
The problem is evolving the interpreter in a way that doesn't break bazillions of third party bindings -- Win32, OpenGL, Fortran for NumPy/Pandas, databases, GPUs, every C and C++ library ever, etc.

Python's C API exposes ref counting and the GIL. It's also very large

JS doesn't have that problem -- more code is written in pure JS, there are no C/C++ bindings in the browser.

There are C/C++ bindings in node.js for v8, but as far as I know they are discouraged and not used very much. The bindings are more "first party" in node.js than third party.

They have issues, but not the same ones as CPython, because the API is very different

JS VMs must be re-entrant because they're embedded in browsers. That was never the case for CPython

Re:Python 3.11.0 final is now available by brrrrrm on Tuesday October 25, 2022 @02:24PM (#33334333)
> as far as I know they are discouraged

Fwiw, this a fully stable and well documented API. It’s not even v8 exclusive, Bun cloned it for WebKit.

https://nodejs.org/api/n-api.html

Re:Python 3.11.0 final is now available by 323 on Tuesday October 25, 2022 @02:26PM (#33334362)
The only C code JavaScript needs to interact with is 100% under the control of the browser implementing that JavaScript engine.

JavaScript doesn't interact with random C libraries that the user might have, like Python does.

Re:Python 3.11.0 final is now available by brrrrrm on Tuesday October 25, 2022 @03:18PM (#33334948)
This is unfortunately a bit misinformed. You are thinking of a specific JavaScript implementation (browsers). The language has heavy adoption in the native space. Check out Node.js!

JavaScript does interact with random C libraries :)

Re:Python 3.11.0 final is now available by insanitybit on Tuesday October 25, 2022 @04:16PM (#33335567)
Yep, although for a very, very long time that wasn't the case.
Re:Python 3.11.0 final is now available by brrrrrm on Tuesday October 25, 2022 @05:08PM (#33336210)
Well, that changed over a decade ago
Re:Python 3.11.0 final is now available by insanitybit on Tuesday October 25, 2022 @05:45PM (#33336577)
But V8 and JIT'd runtimes were already standard for years by the time nodejs came out.
Re:Python 3.11.0 final is now available by donkeyboy on Tuesday October 25, 2022 @07:06AM (#33328904)
They already have jit through numba.
Re:Python 3.11.0 final is now available by pjmlp on Tuesday October 25, 2022 @07:08AM (#33328918)
That is special purpose for one kind of use cases.
Re:Python 3.11.0 final is now available by IanOzsvald on Tuesday October 25, 2022 @11:33AM (#33331981)
Numba focuses on scientific use cases speeding up most of numpy and some of scipy. Whilst it can compile some parts of pure Python (eg numeric array loops), generally you have to copy the data in to the numba side which can be slow in volume. Numba isn't really meant for pure Python speed-ups, it gets rid of numpy specific inefficiencies. Personally I'm pretty excited to see a fresh JIT working its way into core CPython (I'm the co-author of O'Reilly's High Performance Python).
Re:Python 3.11.0 final is now available by kevin_thibedeau on Tuesday October 25, 2022 @02:15PM (#33334224)
The low hanging fruit is to implement something like a built in Cython without any type annotations. You get a speedup from not having bytecode but still have all the PyObject attribute lookups performed from native code.
Re:Python 3.11.0 final is now available by __mharrison__ on Tuesday October 25, 2022 @03:12PM (#33334886)
Something like Psyco from Python 2 days...
Re:Python 3.11.0 final is now available by patrec on Tuesday October 25, 2022 @07:44AM (#33329220)
I think python 3.11 has effectively killed off both Pypy and Pyston. Now that the CPython team has finally shown both willingness and ability to deal with performance problems, few people are going to fool around with some esoteric version of python for an increasingly questionable performance-gains/headache ratio. Especially given how painful it already is to package and deploy normal python code and how hostile Guido always has been to alternative implementations. I don't think being maybe 2x faster right now is anywhere good enough to justify the additional risks and hassle, and it looks like the performance gap might shrink further with 3.12.
Re:Python 3.11.0 final is now available by smcl on Tuesday October 25, 2022 @08:59AM (#33329874)
Pyston may be considered estoreric, but Pypy is pretty well-established already and is still a good deal faster. It could be that CPython starts to eat into its user base as it accumulates more performance gains, but Pypy is definitely not done yet.
Re:Python 3.11.0 final is now available by wirrbel on Tuesday October 25, 2022 @09:39AM (#33330306)
I have been professionally programming Python now since I guess 2012 and its Pypy is an interesting one. Pypy seems to be in use overall in fairly specialized Python application, like research code that is 'too big to rewrite', there are some legacy python applications I heard of successfully running on pypy for years, also you are able to get professional support in onboarding python programs on pypy. So pypy is often used in software that cannot continue to be operated on CPython for performance reasons and rewriting is not feasible / desirable.

Fond memories: I did use pypy or a predecessor in like 2004 I think when I took part in a student computer science competition and my algorithm searching for subgraphs wasn't performing well enough to terminate in time.

Re:Python 3.11.0 final is now available by smcl on Tuesday October 25, 2022 @10:02AM (#33330586)
Ha funny, we have both (ab)used Pypy in exactly the same way :) I had an Advent of Code solution that I implemented horribly in Python, I knew it would spit out the right answer eventually but it was just taking too long. Rather than do a proper rewrite I figured I'd at least try it with Pypy just to see if I could be lazy, and sure enough I got my answer fairly quickly :D
Re:Python 3.11.0 final is now available by patrec on Tuesday October 25, 2022 @10:13AM (#33330706)
Pyston is already in the "our incredible journey" stage ("We’re very excited about these changes and [...] Marius and I (Kevin) are planning to gradually reduce our time investment in the project").

Pypy, as a practical software deployment runtime has been and will remain esoteric (I do absolutely think that they had a positive impact on the wider python community, both in terms of dissemination of ideas and also practical engineering artifacts). But what's their market share relative to CPython? A thousandth of a percent or less? Has anyone actually built a significant business on top of Pypy?

There is, IMO no realistic path at that point that Pypy could become a viable CPython alternative. They are effectively competing with a hostile platform they need to maintain an extremely high amount of compatibility with, and that can and does move in directions that invalidate some fundamental engineering choices they make. Practical end results include that they're stuck w/ a lot of crippling design decisions (GIL, FFI API etc.) and a core part that is still in 2.7 land (RPython) and have historically mostly only been compatible to very outdated versions of python. This has improved a lot, but the next time CPython throws another curve ball the same thing is bound to happen again.

The only chance they really had was to be compellingly enough faster or otherwise superior that community pressure would have forced the CPython team into adopting a much more collaborative stance. That seems very unlikely to happen, now after all this time, given that now CPython is catching up and they have the albatross of the C extension ecosystem around their neck. Almost anyone who cares about python performance outside of algorithmic programming competitions will be using C extensions where Pypy offers no compelling advantage, some disadvantages, and by the momentum of the existing eco-system is unable to develop a superior alternative.

Re:Python 3.11.0 final is now available by jszymborski on Tuesday October 25, 2022 @11:52AM (#33332254)
At least among the scientific community, PyPy's FFI limitations are the main stumbling block. I'm not sure the other factors dissuade much from its adoption in that community (people have just started migrating to 3.6 from 2.7).
Re:Python 3.11.0 final is now available by MiguelX413 on Tuesday October 25, 2022 @11:59AM (#33332378)
I love Pyo3 because of its PyPy compatibility
Re:Python 3.11.0 final is now available by smcl on Tuesday October 25, 2022 @02:42PM (#33334563)
I just didn't think Pypy belonged in the same category as Pyston. There have been a few similar projects - Pyjion, Unladen Swallow and Nuitka also come to mind - each of them are/were impressive pieces of engineering, worthy of our admiration. But each of them have also seemed to hit a wall of some kind and have fallen by the wayside, as you said Pyston has. Meanwhile Pypy has stuck around for fifteen years, it may not be CPython but it'll still be around for a while yet I imagine.
Re:Python 3.11.0 final is now available by ogogmad on Tuesday October 25, 2022 @10:03AM (#33330588)
Pyston is obsolete - but PyPy is still undergoing development; and is significantly faster than CPython as long as the FFI isn't involved. For me, "significantly" has meant 6x on occasions.

Without Pypy, Python is simply a very slow language.

Re:Python 3.11.0 final is now available by dragonwriter on Tuesday October 25, 2022 @12:07PM (#33332482)
> how hostile Guido always has been to alternative implementations.

Isn’t mypyc effectively an alternative (AOT-compiled) Python implementation? Guido doesn’t seem too hostile too it.

Re:Python 3.11.0 final is now available by __mharrison__ on Tuesday October 25, 2022 @03:11PM (#33334872)
Incidentally, I was working on a 15 year old Python 2 project for a client last week that used Pysco (the predecessor for PyPy). The cool thing about Pysco was that you could just import the library and it would make many operations much faster.

If PyPy had a similar mode where you could load it as a library it would have a much easier time gaining traction.

Re:Python 3.11.0 final is now available by alanfranz on Tuesday October 25, 2022 @05:31PM (#33336453)
psyco!
Re:Python 3.11.0 final is now available by miohtama on Tuesday October 25, 2022 @08:06AM (#33329395)
Are there any plans to change Python the language to make it faster? AFAIK most of the slowness comes from dynamic overhead, like object attributes may change or disappear in the middle of a loop and so on.
Re:Python 3.11.0 final is now available by cdavid on Tuesday October 25, 2022 @09:10AM (#33329982)
I doubt so, it would break almost any non trivial piece of python. And the ecosystem is a large reason for current python's success.

Being dynamic make it harder to be fast, but JS/v8 is as dynamic as python, and much faster.

Re:Python 3.11.0 final is now available by jokoon on Tuesday October 25, 2022 @10:41AM (#33331081)
If there was enough money, it would be possible to have a v8 equivalent to python.
Re:Python 3.11.0 final is now available by beagle3 on Tuesday October 25, 2022 @10:43AM (#33331125)
But some dynamic features, e.g. “with” make JS and its JITs give up and run slowly.

Those features are not in common use. Python’s hard-to-optimize dynamic features are more commonly used.

Re:Python 3.11.0 final is now available by mytherin on Tuesday October 25, 2022 @01:30PM (#33333623)
The hardest part about optimizing Python is the fact that there are so many packages out there relying on every single documented and undocumented aspect of the C/C++ interface, which is incredibly broad and directly tied to the internals of the language. If they change anything in a non-backwards compatible manner many of those packages will break, and those packages are the reason so many people use Python to begin with.

Javascript never had this problem, as all code was always written in Javascript itself by necessity, so it was far easier to optimize as you did not have to worry about backwards compatibility of the internals.

Re:Python 3.11.0 final is now available by cdavid on Wednesday October 26, 2022 @10:34AM (#33344334)
That's a excellent point. That ecosystem is also one of the main reason packaging in python is a bit of a clusterf*ck.

For C/C++ extensions, I think there may be hope to support a slow/emulating C API and a faster, less internals-leaking new API that extensions could adopt. It would take years for the migration, but if speed gains was say 5x, I think it could be realistic.

pypy managed to emulate the C API fairly well, after all. E.g. you can build numpy and pandas on top of pypy and it actually kinda works.