Skip to content

gh-149564: Propagate call-site hotness to callees via dynamic exits#149575

Open
anujbharambe wants to merge 1 commit intopython:mainfrom
anujbharambe:gh-149564-jit-dynamic-exit-boost
Open

gh-149564: Propagate call-site hotness to callees via dynamic exits#149575
anujbharambe wants to merge 1 commit intopython:mainfrom
anujbharambe:gh-149564-jit-dynamic-exit-boost

Conversation

@anujbharambe
Copy link
Copy Markdown
Contributor

@anujbharambe anujbharambe commented May 8, 2026

Summary

  • When a hot loop calls many distinct exec()-generated functions, the loop trace fires _DYNAMIC_EXIT on each call because the function version guard fails for each different callee. Each callee's RESUME_CHECK_JIT counter 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.
  • This PR fixes the issue by boosting the callee's RESUME counter to trigger immediately when _DYNAMIC_EXIT or _COLD_DYNAMIC_EXIT lands on a RESUME_CHECK_JIT instruction.
    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_EXIT and _COLD_DYNAMIC_EXIT
  • Python/executor_cases.c.h: Regenerated
  • Lib/test/test_capi/test_opt.py: Added test_dynamic_exit_boosts_resume

Risks

  • Memory: Compiling many small callees increases memory usage. Acceptable since the backoff mechanism prevents runaway recompilation on failure.
  • Overhead: The 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants