GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-141498: Change backoff counter to use prime numbers instead of powers of 2 by efimov-mikhail · Pull Request #141591 · python/cpython Conversation
|
| int backoff = counter.value_and_backoff & BACKOFF_MASK; | ||
| if (backoff < MAX_BACKOFF) { | ||
| return make_backoff_counter((1 << (backoff + 1)) - 1, backoff + 1); | ||
| return make_backoff_counter((1 << (2 * backoff + 3)) - 1, backoff + 1); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since we are changing this, we might as well use a table. It is only 8 entries of 2 bytes each.
See #141498 (comment)
We want 0 to map to 1, and MAX_BACKOFF to map to near 8k.
I think you can make this branchless as well. Something like:
assert(backoff <= MAX_BACKOFF); value = LOOKUP_TABLE[backoff] backoff = backoff == MAX_BACKOFF ? backoff : backoff + 1; return make_backoff_counter(value, backoff);
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In fact, if we store the counter, both value and backoff, in the table. It can be even simpler:
assert(backoff <= MAX_BACKOFF); return LOOKUP_TABLE[backoff];
And have LOOKUP_TABLE[UNREACHABLE_BACKOFF] == LOOKUP_TABLE[MAX_BACKOFF] so non-debug builds do something sensible.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Of course, I'll add using LOOKUP_TABLE in this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, but the values in the table need to be moved one position:
Instead of 6, 30, ... , 8190, 8190, 8190 it should be 1, 6, 30, ... , 8190, 8190
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // We only use values x and backoffs b such that | ||
| // x + 1 is near to 2**(2*b+1) and x + 1 is prime. | ||
| static const uint16_t value_and_backoff_next[] = { | ||
| MAKE_VALUE_AND_BACKOFF(6, 1), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This needs to be MAKE_VALUE_AND_BACKOFF(1, 1) so that code is re-specialized quickly when the cooldown counter expires.
See https://github.com/python/cpython/blob/main/Include/internal/pycore_code.h#L445
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oops, sorry for this mistake. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
Thanks
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.