-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Generation of tier 2 traces is overly optimistic about the accuracy of profiling for branches. #115727
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
Comments
@gvanrossum this might be of interest to you |
Temporary fix of confidence score test.
I tried to use lltrace debugging to understand better what's happening here (you probably already know this). A few issues contribute to the seemingly random behavior if the test is repeatedly called after resetting optimizers and executors. I simulated this effect as follows: def test_repeat_confidence_score(self):
for _ in range(10):
self.test_confidence_score()
sys._clear_internal_caches() One of the things I learned is that it's not just the bitmasks in the This has the interesting effect that the first run is different than all later runs: the first time, the counter starts at 0 and we optimize when it has hit the threshold (16), so we execute 16 iterations in Tier 1. But all later runs (well, until our poor signed 12 bits counter overflows) execute a single Tier 1 iteration, find the counter already > 16, and immediately optimize. Since the initial iteration is always executed in Tier 1, and the jump bitmask is only updated in Tier 1, and the first iteration always has All in all we now find that for the second and following calls to Is there a bug here? We might argue that we don't care -- this is obviously an unusual situation, regular apps won't be resetting the optimizer or clearing the executors, so the rolling over of the counter in |
The first half of this is simple (it changes the multiplier to something in the range 0.5-0.9 instead of 0.5-1.0), and I'll send a PR for this. I'm not sure what to do for
Assuming you're referring to Assuming
I'm not ready for that yet. With the current threshold (1/3), it would take over 10 maximally-confident jumps to end the trace early -- that's gotta be very branchy code indeed. :-) For unpredictable jumps, there is no difference. |
The theory is that even if we saw a jump go in the same direction the last 16 times we got there, we shouldn't be overly confident that it's still going to go the same way in the future. This PR makes it so that in the extreme cases, the confidence is multiplied by 0.9 instead of remaining unchanged. For unpredictable jumps, there is no difference (still 0.5). For somewhat predictable jumps, we interpolate.
…5728) Temporary fix of confidence score test.
…on#115748) The theory is that even if we saw a jump go in the same direction the last 16 times we got there, we shouldn't be overly confident that it's still going to go the same way in the future. This PR makes it so that in the extreme cases, the confidence is multiplied by 0.9 instead of remaining unchanged. For unpredictable jumps, there is no difference (still 0.5). For somewhat predictable jumps, we interpolate.
…5728) Temporary fix of confidence score test.
…on#115748) The theory is that even if we saw a jump go in the same direction the last 16 times we got there, we shouldn't be overly confident that it's still going to go the same way in the future. This PR makes it so that in the extreme cases, the confidence is multiplied by 0.9 instead of remaining unchanged. For unpredictable jumps, there is no difference (still 0.5). For somewhat predictable jumps, we interpolate.
…5728) Temporary fix of confidence score test.
…on#115748) The theory is that even if we saw a jump go in the same direction the last 16 times we got there, we shouldn't be overly confident that it's still going to go the same way in the future. This PR makes it so that in the extreme cases, the confidence is multiplied by 0.9 instead of remaining unchanged. For unpredictable jumps, there is no difference (still 0.5). For somewhat predictable jumps, we interpolate.
Bug report
We have a test for our confidence that the trace is going the right way:
But consider this:
The direction of the branch changes every 16 iterations, so looks perfectly predictable to profiling but it as pathalogical as the first version.
How to fix this
We should lower our confidence a bit, even if profiling claims 100% predictability.
I don't think there is a perfect way to do this, but it shouldn't too hard to come up with something good enough.
Here is a possible scheme
Use lower confidence and threshold when generating the initial trace:
is None
checks)Reassess confidence in optimizer:
Linked PRs
The text was updated successfully, but these errors were encountered: