News for hackers. Stuff that matters.
Re:Faster CPython at PyCon, part one by TwentyPosts on Thursday May 11, 2023 @11:26AM (#35903543)
Somehow I'm still skeptical! Feels like "strict superset of Python, all Python code works" and "several orders of magnitude faster" just sounds like you're trying to have your cake and eat it, too.

I doubt that the Mojo developers have some sort of 'secret sauce' or 'special trick' that will get them there. And even if they have something, I don't see why the Python devs wouldn't just implement the same approach, considering they're currently trying to make Python faster.

I assume that (as long as Mojo wants to stick to its goal of being a strict superset of Python), there will be a lot of things that just cannot be 'fixed'. For example, I'd be surprised if Python's Global Interpreter Lock isn't entangled with the language in a few nasty ways that'd make it really difficult to replace or improve upon (while retaining compatibility).

Then again, the developer of Swift is working on it, right? I guess he's got the experience, at least.

Re:Faster CPython at PyCon, part one by wiseowise on Thursday May 11, 2023 @11:34AM (#35903661)
Isn’t Mojo compiled? While Python needs to be interpreted.
Re:Faster CPython at PyCon, part one by TwentyPosts on Thursday May 11, 2023 @11:54AM (#35903996)
Mojo bothers offers Just-In-Time and Ahead-Of-Time models. Proper AOT compilation is going to offer a significant speedup, but probably not enough to get to their stated goals. And good luck carrying all of Python's dynamic features across the gap.
Re:Faster CPython at PyCon, part one by mikepurvis on Thursday May 11, 2023 @12:04PM (#35904165)
I think the point is that it's really hard to get those gains from "being compiled" when every function or method call, every use of an operator, everything is subject to multiple levels of dynamic dispatch and overrideability, where every variable can be any type and its type can change at any time and so has to be constantly checked.

A language that's designed to be compiled doesn't have these issues, since you can move most of the checking and resolution logic to compile-time. But doing that requires the language's semantics to be aligned to that goal, which Python's most certainly are not.

The achievements of Pypy are pretty incredible in the JIT space, but the immense effort that has gone in there definitely is a good reason to be skeptical of Mojo's claims of being both compiled and also a "superset" of Python.

Re:Faster CPython at PyCon, part one by waterhouse on Thursday May 11, 2023 @04:53PM (#35908245)
So you want a system that figures out that the vast majority of function and method calls are not overridden, that these variables and fields are in practice always integers, etc.; generates some nice compiled code, and adds some interlock so that, if these assumptions do change, the code gets invalidated and replaced with new code (and maybe some data structures get patched).

I think that this kind of thing is in fact done with the high-performing Javascript engines used in major browsers. I imagine PyPy, being a JIT, is in a position to do this kind of thing. Perhaps Python is more difficult than Javascript, and/or perhaps a lot more effort has been put into the Javascript engines than into PyPy?

Re:Faster CPython at PyCon, part one by mikepurvis on Thursday May 11, 2023 @10:38PM (#35911266)
Python is considerably more dynamic than JavaScript. And I'm not trying to drag pypy, just saying that that's already the state of the art and there are good reasons that the authors of pypy didn't set out to do what Mojo apparently claims to have done.
Re:Faster CPython at PyCon, part one by tgma on Friday May 12, 2023 @03:54PM (#35921441)
> Python is considerably more dynamic than JavaScript

This is sometimes repeated but I don’t believe that is why Python is slow (nor do I think for most measures of “dynamic” it is even true). Which aspect of “dynamism” in particular are you concerned about that JavaScript lacks? The primary hindrance is keeping CPython extensions working while making Python fast. Add to that the hundreds of millions that went into V8 and other JavaScript implementation efforts.

Re:Faster CPython at PyCon, part one by int_19h on Friday May 12, 2023 @06:42PM (#35923462)
For starters, consider that almost every operator in Python is a dynamic method call under the hood. This includes value equality and hashing, which also affects e.g. dict keys. Oh, and all built-in types can be extended and their behavior overridden.

And then there's descriptors: https://docs.python.org/3/howto/descriptor.html

Re:Faster CPython at PyCon, part one by tgma on Friday May 12, 2023 @10:31PM (#35924903)
Those are hardly unsolvable issues with a JIT as they are static for the vast majority of cases. Solutions have been proposed since the 90s with Self and Strongtalk[1].

Doing that, plus 100% compatibility with CPython extension API, while preserving some expectations of deterministic destruction in Python, are the challenges one would face.

[1]: http://www.strongtalk.org/

Re:Faster CPython at PyCon, part one by jjnoakes on Thursday May 11, 2023 @10:30PM (#35911210)
The point is that the part of mojo that is new allows you to write early bindings that can't change, immutable variables, values that are accessed without indirection, types, ownership annotations, etc, and uses all of that to do precisely what you are asking for.
Re:Faster CPython at PyCon, part one by mikepurvis on Thursday May 11, 2023 @10:41PM (#35911286)
If it can't do much until those extra annotations are in place, then I would imagine it's unlikely it'll ever get support from numpy, django, and the like. Uptake for mypy type annotations alone has been pretty slow.
Re:Faster CPython at PyCon, part one by carlmr on Friday May 12, 2023 @01:32AM (#35912279)
>Uptake for mypy type annotations alone has been pretty slow.

Because they're annotations with bad checkers. They're mostly helpful as documentation.

TypeScript checking is on a whole different level.

Re:Faster CPython at PyCon, part one by pjmlp on Friday May 12, 2023 @01:38AM (#35912320)
Python can be JIT compiled, so far most efforts failed short due to CPython FFI API.

Plenty of other dynamic languages have proven the point already.

Re:Faster CPython at PyCon, part one by Conscat on Thursday May 11, 2023 @11:50AM (#35903940)
Well, they do have MLIR, which is probably the closest thing to "secret sauce" they've got. I'm excited by some of the performance-oriented features like tiling loops, but they'll need the multitude of optimization-hints that GCC and Clang have, too. They also have that parallel runtime, which seems similar to Cilk to me, and Python fundamentally can never have that as I understand it.
Re:Faster CPython at PyCon, part one by umanwizard on Thursday May 11, 2023 @11:55AM (#35904016)
IDK about 35,000x but Python really is outrageously slow relative to other popular languages, even other interpreted ones. It's more comparable to something like Ruby than to something like JavaScript.
Re:Faster CPython at PyCon, part one by williamstein on Thursday May 11, 2023 @01:04PM (#35905005)
From their FAQ: "How compatible is Mojo with Python really? Mojo already supports many core features of Python including async/await, error handling, variadics, etc, but… it is still very early and missing many features - so today it isn’t very compatible. Mojo doesn’t even support classes yet!".

Overall, pure Python seems to be about 100x slower than what you can reasonably get with a compiled language and some hard work. It's about 10x slower than what you can get from JITs like Pypy and Javascript, when such comparisons makes sense.

I agree that Mojo remind me of Cython, but with more marketing and less compatibility with Python. Cython aspired to be a nearly 99% superset of Python, at least that's exactly what I pushed my postdocs and graduate students to make it be back in 2009 (e.g., there were weeks of Robert Bradshaw and Craig Citro pushing each other to get closures to fully work). Mojo seems to be a similar modern idea for doing the same sort of thing. It could be great for the ecosystem; time will tell. Cython could still also improve a lot too -- there is a major new 3.0 release just around the corner!: https://pypi.org/project/Cython/#history

Re:Faster CPython at PyCon, part one by pavon on Thursday May 11, 2023 @11:58AM (#35904077)
I am a little skeptical as well, but I do think there is a lot of areas for improvement beyond the changes going in mainline. Note that while Mojo intends to support all of python, they never claimed that it will still be fast if you make heavy use of all the dynamic features. The real limiting factors are how often those dynamic features are used, and how frequently the code needs to be checking whether they are used.

The fast CPython changes are still very much interpreter-centric, and are checking whether assumptions have changed on every small operation. It seems to me that if you are able to JIT large chunks of code, and then push all the JIT invalidation checks into the dynamic features that break your assumptions rather than in the happy path that is using the assumptions, you ought to be able to get much closer to to Javascript levels of performance when dynamic features aren't being used.

Then support for those dynamic features becomes a fallback way of having a huge ecosystem from day one, even if it is only modestly faster than CPython.

Re:Faster CPython at PyCon, part one by spprashant on Thursday May 11, 2023 @03:20PM (#35907061)
The way I read it, Python code as it is, won't see a huge bump it's like 10x or something.

You have to use special syntax and refactoring to get the 1000x speed ups. The secret sauce is essential a whole new language within the language which likely helps skip the GIL issues.

Re:Faster CPython at PyCon, part one by jck on Friday May 12, 2023 @01:00PM (#35918895)
Do they claim that existing python code would get a 10x bump? That sounds too good to be true
Re:Faster CPython at PyCon, part one by mirekrusin on Thursday May 11, 2023 @11:29PM (#35911541)
...Swift and creator of LLVM and Clang.