| ▲ | rslashuser 12 hours ago |
| I'm curious is the JIT developers could mention any Python features that prevent promising JIT features. An earlier Ken Jin blog [1], mentions how __del__ complicates reference counting optimization. There is a story that Python is harder to optimize than, say, Typescript, with Python flexibility and the C API getting mentioned. Maybe, if the list of troublesome Python features was out there, programmers could know to avoid those features with the promise of activating the JIT when it can prove the feature is not in use. This could provide a way out of the current Python hard-to-JIT trap. It's just a gist of an idea, but certainly an interesting first step would be to hear from the JIT people which Python features they find troublesome. [1] https://fidget-spinner.github.io/posts/faster-jit-plan.html |
|
| ▲ | rtpg 12 hours ago | parent | next [-] |
| It's interesting you mention __del__ because Javascript not only doesn't have destructors but for security reasons (that are above my pay grade) but the spec _explicitly prohibits_ implementations from allowing visibility into garbage collection state, meaning that code cannot have any visibility into deallocations. I think __del__ is tricky though. In theory __del__ is not meant to be reliable. In practice CPython reliably calls it cuz it reference counts. So people know about it and use it (though I've only really seen it used for best effort cleanup checks) In a world where more people were using PyPy we could have pressure from that perspective to avoid leaning into it. And that would also generate more pressure to implement code that is performant in "any" system. |
| |
| ▲ | cpgxiii 11 hours ago | parent | next [-] | | > In practice CPython reliably calls it cuz it reference counts ... In a world where more people were using PyPy we could have pressure from that perspective to avoid leaning into it A big part of the problem is that much of the power of the Python ecosystem comes specifically from extensions/bindings written in languages with manual (C) or RAII/ref-counted (C++, Rust) memory management, and having predictable Python-level cleanup behavior can be pretty necessary to making cleanup behavior in bound C/C++/Rust objects work. Breaking this behavior or causing too much of a performance hit is basically a non-starter for a lot of Python users, even if doing so would improve the performance of "pure" Python programs. | | |
| ▲ | mattip 6 hours ago | parent [-] | | That cleanup can be explicit when needed by using context managers. Mixing resource handling with object lifetime is a bad design choice |
| |
| ▲ | nvme0n1p1 12 hours ago | parent | prev | next [-] | | > code cannot have any visibility into deallocations Doesn't FinalizationRegistry let you do exactly that? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... | | |
| ▲ | alpinisme 11 hours ago | parent | next [-] | | That link itself calls out that conformant implementations can’t be relied on to call callbacks. > A conforming JavaScript implementation, even one that does garbage collection, is not required to call cleanup callbacks. When and whether it does so is entirely down to the implementation of the JavaScript engine. When a registered object is reclaimed, any cleanup callbacks for it may be called then, or some time later, or not at all.
It's likely that major implementations will call cleanup callbacks at some point during execution, but those calls may be substantially after the related object was reclaimed. Furthermore, if there is an object registered in two registries, there is no guarantee that the two callbacks are called next to each other — one may be called and the other never called, or the other may be called much later.
There are also situations where even implementations that normally call cleanup callbacks are unlikely to call them: | | |
| ▲ | bastawhiz 11 hours ago | parent [-] | | It's supported in all of the major engines. And you also can't rely on the garbage collector to run at a predictable time (or at all!), so the engine never calling finalizers is functionally the same as the garbage collector being unusual. | | |
| ▲ | sfink 6 hours ago | parent [-] | | The only (other) visible effect of GC not running is memory exhaustion. WeakRef/FinalizationGroup not getting triggered can have lots of script-visible effects, so can be much much worse. I wouldn't describe that as "functionally the same". |
|
| |
| ▲ | rtpg 11 hours ago | parent | prev [-] | | Oh! While this one does mention that you don't have visibility, this + weak refs seem to change the game I remember a couple of years ago (well probably around 2021) reading about GC exposure concerns and seeing some line in some TC39 doc like "users should not have visibility into collection" but if we've shipped weakrefs sounds like we're not thinking about that anymore | | |
| ▲ | sfink 6 hours ago | parent [-] | | We still try to limit any additional exposure as much as possible, and WR/FG are specced to keep the visibility as coarse as possible. (Collections won't be visible until the current script execution finishes, though async adds a lot more places where that can happen.) A proposal to add new ways of observing garbage collection will still be shot down immediately without a damn good justification. |
|
| |
| ▲ | jonathanlydall 7 hours ago | parent | prev | next [-] | | > meaning that code cannot have any visibility into deallocations. This is more pedantry than a serious question. JavaScript has WeakReference, sure it'd be cumbersome and inefficient because you'd need to manually make and poll each thing you wanted to observe, but could it not be said that it does provide a view on deallocations? | | |
| ▲ | sfink 6 hours ago | parent [-] | | Yes, WeakRef and FinalizationGroup both make GC visible (the latter removes the need to poll in your example). So not pedantic at all. They were eventually added after much reluctance from the language designers and implementers, partly because they can lead to code being broken by (valid & correct) engine optimizations, which is a big no-no on the web. But some things simply cannot be implemented without them. Note that 90% of the uses for them actually shouldn't be using them, usually for subtle reasons. It's always a big cause for debate. |
| |
| ▲ | 11 hours ago | parent | prev [-] | | [deleted] |
|
|
| ▲ | kstrauser 10 hours ago | parent | prev | next [-] |
| Huh, I could imagine that as a set of Ruff rules: > Using str.frobnicate prevents TurboJit on line 63 |
|
| ▲ | adgjlsfhk1 12 hours ago | parent | prev [-] |
| The biggest thing is BigInt by default. It makes every integer operation require an overflow check. |
| |