-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-115999: Enable free-threaded specialization of LOAD_CONST #129365
Conversation
I'm not sure why LOAD_CONST was already checked off on the issue page. The test fails for free-threaded builds without the accompanying bytecode change. |
I think specializing |
Looks like about 1% gain from this, but given noise levels it could be a wash. Still, considering way more things are currently immortal in the free-threaded build it's probably a bigger win than in the regular build :D |
Python/generated_cases.c.h
Outdated
uint8_t expected = LOAD_CONST; | ||
_Py_atomic_compare_exchange_uint8( | ||
&this_instr->op.code, &expected, | ||
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want a bigger win, perhaps you could allow deferred references as well. They behave the same as immortal objects if they're live on the stack.
Considering many LOAD_CONST are deferred objects, that should be a nice win in perf.
That can come in another PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's probably a good idea. Running some tests on the testsuite, about 75% of all LOAD_CONST invocations involved immortal objects, 25% were deferred, and the remainder is less than 1% (in the free-threaded build. Not nearly as many immortal objects in a regular build). I suspect we'll get fewer immortal objects over time, and most of them will probably be deferred instead, I guess?
Now the question is: do I add PyStackRef_FromPyObjectDeferred()
, or do I change PyStackRef_FromPyObjectImmortal()
to accept deferred objects as well? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Enable free-threaded specialization of LOAD_CONST, which is an unconditional specialization without stats bookkeeping, so it's a simple opcode replace. (It could even be a relaxed store if we didn't have to worry about instrumentation.)
--disable-gil
builds #115999