-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Branch confidence decay in Tier 2 translator #112320
Comments
gvanrossum
changed the title
BranchBrahch confidence decay in Tier 2 translator
Branch confidence decay in Tier 2 translator
Nov 22, 2023
gvanrossum
added a commit
that referenced
this issue
Dec 12, 2023
We track the confidence as a scaled int.
aisk
pushed a commit
to aisk/cpython
that referenced
this issue
Feb 11, 2024
…ython#112321) We track the confidence as a scaled int.
Closing because the PR has been merged. Please re-open if there's more needed here. |
Thanks, and sorry. I usually forget to use the "fixes gh-blahblah" magic phrase. :-( |
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this issue
Sep 2, 2024
…ython#112321) We track the confidence as a scaled int.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a follow-up to gh-109039 (and to a lesser extent gh-111848). (I'm sure I read about it somewhere on https://github.com/faster-cpython/ideas/issues too, but I can't find the relevant issue, so I'll describe the idea from scratch here.)
When we translate a branch instruction (e.g.
POP_JUMP_IF_TRUE
), Tier 1 has a 16-bit shift register tracking how often we branched in the past 16 times this instruction was reached. During Tier 2 translation, if the bit count indicates that we've taken the branch more often than not, we continue the trace at the branch destination; otherwise, we continue following the branch instruction.What we should also do in the translator have a variable (for the entire trace) indicating how likely we are still "on trace". This "confidence factor" starts off at 100%. If we translate a branch that is taken X% of the time, for X >= 50%, we should multiply the confidence by X%. If the confidence ends too low (say, below 33%) we should end the trace at this point, generating an
_EXIT_TRACE
uop.UPDATE: Ideally we should also adjust the confidence each time we generate a guard. But what factor should we use there? Most guards fail rarely. I propose to punt on this now; later we can add code to adjust the same variable on deoptimization exits.
Linked PRs
The text was updated successfully, but these errors were encountered: