News for hackers. Stuff that matters.
Re:Python 3.15's JIT is now back on track by dekelpilli on Wednesday March 18, 2026 @01:16AM (#47421826)
Java also has a performance cost to accessing class fields, as exampled by this (now-replaced) code in the JDK itself - https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/...
Re:Python 3.15's JIT is now back on track by anematode on Wednesday March 18, 2026 @02:25AM (#47422188)
Any decent JIT compiler (and HotSpot's is world class) will optimize this out. Likely this was done very early on in development, or was just to reduce bytecode size to promote inlining heuristics that use it
Re:Python 3.15's JIT is now back on track by LtWorf on Wednesday March 18, 2026 @03:26AM (#47422620)
But what if whatever you call is also accessing and changing the attribute?
Re:Python 3.15's JIT is now back on track by anematode on Wednesday March 18, 2026 @03:34AM (#47422686)
If what you call gets inlined, then the compiler can see that it either does or doesn't modify the attribute and optimize it accordingly. Even virtual calls can often be inlined via, e.g., class hierarchy analysis and inline caches.

If these analyses don't apply and the callee could do anything, then of course the compiler can't keep the value hoisted. But a function call has to occur anyway, so the hoisted value will be pushed/popped from the stack and you might as well reload it from the object's field anyway, rather than waste a stack slot.

Re:Python 3.15's JIT is now back on track by LtWorf on Wednesday March 18, 2026 @10:19AM (#47426119)
Another thread can access it and do that, how could the compiler possibly know about it?
Re:Python 3.15's JIT is now back on track by bmm6o on Wednesday March 18, 2026 @01:46PM (#47428879)
There are documented ways to ensure that changes are visible across threads (e.g. locks). If these are not used, the compiler is within its rights to not go out of its way to pull changes from another thread.
Re:Python 3.15's JIT is now back on track by LtWorf on Wednesday March 18, 2026 @04:58PM (#47431365)
Except python has a well documented global lock.
Re:Python 3.15's JIT is now back on track by anematode on Wednesday March 18, 2026 @05:56PM (#47431923)
This thread is discussing Java, not Python
Re:Python 3.15's JIT is now back on track by LtWorf on Thursday March 19, 2026 @02:49AM (#47435799)
java has private attributes, python does not
Re:Python 3.15's JIT is now back on track by vanderZwan on Wednesday March 18, 2026 @06:42AM (#47423918)
String is also a pretty damn fundamental object, and I'm sure trim() calls are extremely common too. I wouldn't be surprised if making sure that seemingly small optimizations like this are applied in the interpreter before the JIT kicks are not premature optimizations in that context.

There might be common scenarios where this had a real, significant performance impacts, E.G. use-cases where it's such a bottle-neck in the interpreter that it measurably affects warm-up time. Also, string manipulation seems like the kind of thing you see in small scripts that end before a JIT even kicks in but that are also called very often (although I don't know how many people would reach for Java in that case.

EDIT: also, if you're a commercial entity trying to get people to use your programming language, it's probably a good idea to make the language perform less bad with the most common terrible code. And accidentally quadratic or worse string manipulation involving excessive calls to trim() seems like a very likely scenario in that context.

Re:Python 3.15's JIT is now back on track by bjourne on Thursday March 19, 2026 @06:40AM (#47437255)
Untrue. Objects and attributes may be shared by threads so attribute accesses can't in general be localized.
Re:Python 3.15's JIT is now back on track by anematode on Friday March 20, 2026 @03:27AM (#47451556)
It is true! If you explicitly synchronize between threads, sure, you can't optimize it in general, but if not, the compiler is well within its rights to cache the access.
Re:Python 3.15's JIT is now back on track by bjourne on Saturday March 21, 2026 @01:33PM (#47469197)
Sure, if the compiler can prove that the objects are thread-local. But that's not the general case.
Re:Python 3.15's JIT is now back on track by Kamii0909 on Wednesday March 18, 2026 @05:26AM (#47423453)
That was a niche optimization primarily targeting code at intepretor. Even the most basic optimizing compiler in HotSpot tiered compilation chain at that time (the client compiler or C1) would be able to optimize that into the register. Since String is such an important class, even small stuffs like this is done.