Skip to content
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

Closed
gvanrossum opened this issue Nov 22, 2023 · 2 comments
Closed

Branch confidence decay in Tier 2 translator #112320

gvanrossum opened this issue Nov 22, 2023 · 2 comments

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Nov 22, 2023

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

@gvanrossum 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
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
@hugovk
Copy link
Member

hugovk commented Mar 15, 2024

Closing because the PR has been merged. Please re-open if there's more needed here.

@hugovk hugovk closed this as completed Mar 15, 2024
@gvanrossum
Copy link
Member Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants