-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Improve performance of generating random WebSocket mask #8667
Conversation
The mask was being generated with randint and than converted to bytes. We can skip a few steps and generate it with getrandbits() and pack it into bytes.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8667 +/- ##
=======================================
Coverage 97.97% 97.97%
=======================================
Files 107 107
Lines 33790 33791 +1
Branches 3969 3969
=======================================
+ Hits 33106 33107 +1
Misses 507 507
Partials 177 177
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
thanks |
Backport to 3.10: 💚 backport PR created✅ Backport PR branch: Backported as #8668 🤖 @patchback |
(cherry picked from commit 406cd2c)
Backport to 3.11: 💚 backport PR created✅ Backport PR branch: Backported as #8669 🤖 @patchback |
(cherry picked from commit 406cd2c)
…random WebSocket mask (#8668) Co-authored-by: J. Nick Koston <nick@koston.org>
…random WebSocket mask (#8669) Co-authored-by: J. Nick Koston <nick@koston.org>
What do these changes do?
The mask was being generated with randint and than converted to bytes. We can skip a few steps and generate it with getrandbits() and pack it into bytes.
related RFC: https://datatracker.ietf.org/doc/html/rfc6455#section-5.3
Are there changes in behavior for the user?
No
Is it a substantial burden for the maintainers to support this?
no
I was looking at pings and noticed that most of the time is spent in randrange