You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change backoff counter to have larger range and backoff more quickly. #141498
The backoff counter, _Py_BackoffCounter, supports exponential backoff and a value up to 4095.
Backoff is exponential in powers 2.
There are two issues with this:
It is a bit slow to backoff: specialization and JIT optimizer failures are rarely transient, so we are wasting effort with backoffs like 2, 4, 8,...
It has a relatively low limit of 4095 forcing re-specialization/trace recording every 4095 iteration at most.
The fix is simple, increase the power from 2 to 4. This means we only need 3 bits for the backoff and we get a higher maximum of 8191.
We can also use a lookup table, to ensure that the number of iteration until the next specialization/jit is a prime number
I've created a PR with minimal fix: 12 + 4 bits -> 13 + 3 bits, value = 2**backoff - 1 -> value = 2**(2*backoff+1) - 1.
I can add using prime numbers to the same PR, if we want to.
Activity
efimov-mikhail commentedon Nov 15, 2025
I'd like to work on this, if you're not against it, @markshannon.
efimov-mikhail commentedon Nov 15, 2025
I've created a PR with minimal fix: 12 + 4 bits -> 13 + 3 bits,
value = 2**backoff - 1->value = 2**(2*backoff+1) - 1.I can add using prime numbers to the same PR, if we want to.
CC @Fidget-Spinner
markshannon commentedon Nov 19, 2025
I did some work on it, but I'm happy for you to do it. It looks like you already are 🙂
gh-141498: Change backoff counter to use prime numbers instead of pow…
pythongh-141498: Change backoff counter to use prime numbers instead …
pythongh-141498: Change backoff counter to use prime numbers instead …