gh-149564: Propagate call-site hotness to callees via dynamic exits#149575
gh-149564: Propagate call-site hotness to callees via dynamic exits#149575anujbharambe wants to merge 3 commits intopython:mainfrom
Conversation
picnixz
left a comment
There was a problem hiding this comment.
I'm not very familiary with this part of the code, but I don't like having an LLM touch the bytecode properly. In addition, I don't think dynamic exits are really common apart from specific use cases, and we need to see how it affects regular code (we are still adding checks). So I would suggest that we first discuss whether the feature is acceptable before creating a PR, especially with LLM. This is valid for any issues: don't create PRs unless we reached a consensus.
| // If we're landing on a callee's RESUME, boost its counter so it | ||
| // gets traced sooner (it was called from a hot trace). | ||
| if (target->op.code == RESUME_CHECK_JIT) { | ||
| target[1].counter = trigger_backoff_counter(); |
There was a problem hiding this comment.
How can it "boost" its counter? This sets its counter to 0 here. So it resets it. Not boost it.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Summary
exec()-generated functions, the loop trace fires_DYNAMIC_EXITon each call because the function version guard fails for each different callee. Each callee'sRESUME_CHECK_JITcounter starts high and only decrements by 1 per call, so with ~60 calls per callee, the counter never reaches zero and the callee never gets its own executor._DYNAMIC_EXITor_COLD_DYNAMIC_EXITlands on aRESUME_CHECK_JITinstruction.Being called from a hot trace via dynamic exit is strong evidence the callee deserves compilation.
Changes
Python/bytecodes.c: Added counter boost logic to_DYNAMIC_EXITand_COLD_DYNAMIC_EXITPython/executor_cases.c.h: RegeneratedLib/test/test_capi/test_opt.py: Addedtest_dynamic_exit_boosts_resumeRisks
if (target->op.code == RESUME_CHECK_JIT)check is a single byte comparison on the dynamic exit path (already cold/rare). Negligible cost.AI Disclosure: Some parts of the code and this PR were written with the help of Claude(AI).