Use faster generator for link IDs#3845
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3845 +/- ##
=======================================
Coverage 97.87% 97.87%
=======================================
Files 96 96
Lines 8370 8372 +2
=======================================
+ Hits 8192 8194 +2
Misses 178 178
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Rebased on 14.2. Gentle review request nudge, @willmcgugan? |
37ac060 to
fb43279
Compare
|
Codespell being red is unrelated. |
|
Gentle nudge, @willmcgugan? 😄 |
Type of changes
Checklist
AI?
AI was not used to generate this PR.
Description
I was profiling some code that uses
richand noticed that some unusual time was spent inrandom.getrandbits()(which underliesrandom.randint()). The default RNG in Python is not the fastest to begin with (which is why e.g.fastrandis a thing).This PR switches the generator for
_link_ids from a random number to a simple sequential counter (initialized once with randomness). This also has the happy side effect that link ID collisions are simply not possible anymore, whereas the birthday paradox saysrandom.randint(0, 999999)tends to have a collision in the first 1,253 calls.Running
shows that the new generator is about 8 times faster than the old one (0.381s vs 3.056s).