[–] gopalv 2 days ago
If all python had was __slots__ then we would not be struggling to JIT python.
Tight numerical loops is where the JIT adds performance.
Most performance sensitive features are already available in python between numpy, numba and Cython without really leaving the language core.
You'll mostly be speeding up the slow parts of python, not supercharging the fast parts.
[–] hermitdev 2 days ago
Heh, how about how `__class__` works? Not that I recommend actually doing this, but you can literally change the type of an already instantiated object by reassigning `__class__`:
>>> class Dog:
... def hi(self):
... print("woof")
...
>>> class Cat:
... def hi(self):
... print("meow")
...
>>> dog = Dog()
>>> dog.hi()
woof
>>> dog.__class__ = Cat
>>> dog.hi()
meow
>>> isinstance(dog, Dog)
False
>>> isinstance(dog, Cat)
True
>>>[–] samatman 2 days ago
[–] sakesun 2 days ago
>>> Dog.__bases__ = (Cat,)
>>> isinstance(dog, Dog)
True
>>> isinstance(dog, Cat)
True
>>>[–] gregdeon 2 days ago
[–] esprehn 2 days ago
See also the warning here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
And this related article:
[–] mirashii 2 days ago
[–] lefra 2 days ago
Modifying a variable that is read by another thread needs special care in all multithreaded languages I know. If you don't use a synchronization primitive to tell the other thread "hey, this thing here may have changed, read it again from memory"; the other thread is free to use its old value for as long as it whishes.
[–] pjmlp 2 days ago
[–] cpburns2009 2 days ago
[–] hinkley 2 days ago
I saw this presented as new tech at either OOPSLA or OSCon almost exactly 20 years ago.
CPU branch prediction is still pretty good even with the loss of function in recent years.
[–] Sesse__ 2 days ago
[–] cpburns2009 1 day ago
[–] hinkley 16 hours ago
[–] gobdovan 2 days ago
[–] rurban 2 days ago
[–] pjmlp 2 days ago
[–] yxhuvud 2 days ago
Not since before Ruby 1.9, no.
[–] benrutter 2 days ago
Wait, how many? I'd say just this one. The other that I know of, pypy, was massively successful for a single maintainer project. And definitely showed the possibility/potential of JIT python.
I wouldn't call it a failure for not over taking mainline CPython.
[–] pitrou 1 day ago
> Wait, how many? I'd say just this one.
I can name at least a couple others: Unladen Swallow, Pyston.
> The other that I know of, pypy, was massively successful for a single maintainer project.
PyPy had multiple active core developers during the 2000s.
[–] necovek 2 days ago
[–] xorcist 2 days ago
Have you seen Ruby?
[–] KerrAvon 2 days ago
I don't know Python's innards well enough to understand why it's so especially difficult in this regard, but I gather around the edges that its object model may not be as well founded.
[–] jashmatthews 2 days ago
https://arxiv.org/html/2609.01502v1
[–] pjmlp 2 days ago
All just as dynamic as Python, and with quite usable JIT compilers.
Or for that matter, PyPy and GraalPy do exist.
[–] cdavid 1 day ago
The python C API is the "killer app" of python, and what gave its edge against otherwise similar languages (ruby/js). That's makes it unique (the whole scientific stack). But a lot of early choices leaked into this API, and this (+ preference from guido for simple implementation) is at odds with doing JIT: lots of global state (instead of explicitly passing interpreter state), ref counting, no tagged pointers meaning boxing/unboxing everywhere, etc. Some of those are getting gradually fixed, but that's a slog, though maybe AI can accelerate a lot.
I had high hopes for HPy but that unfortunately fizzled out.
[–] necovek 2 days ago
Can you just replace CPython with PyPy or GraalPy in every project? And why not? :)
[–] pjmlp 2 days ago
PyPy and GraalPy then never get to use those pseudo "Python" libraries, because their API for C based extensions differs enough that you cannot take a random shared library and load them into either.
They came up with a common C API proposal, but has hardly taken that much adoption.
[–] necovek 2 days ago
[–] cyberax 2 days ago
JavaScript also has monkey-patching, and it's also very common. E.g. SolidJS replaces objects with dependency-tracking proxies.
There are really no fundamental language reasons why Python should be more complex. From what I heard from a JIT developer, the main issue is not the code itself but the module system and code loading.
JavaScript was designed from the start to operate inside a sealed environment with only few external handles, with the code loaded upfront or added on-demand via "eval". Not so for Python, where native code modules can (and will) result in code loaded dynamically and it's hard to track what depends on what.
[–] pjmlp 2 days ago
Yet both languages are on the genesis of modern JIT compilers, going beyond what was already being done for Lisps, Prolog, BASIC.
[–] exyi 2 days ago
And the proxies make it slow as Python. Plain objects cannot suddenly become proxies, so the runtime can treat them as a special case.
[–] mistrial9 2 days ago
someone please think of the monkey patchers!