-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Speed up Signals when there are no receivers. #2229
Conversation
Reduce the footprint of the `send()` method by a 10% when there are no receivers connected.
Nice! Since this is a FrozenList, his length is constant. What if you compute length once at Update: I always forgot that it's not frozen like frozenset. Ok, what if do the same - compute length once on freeze while keep it dynamic while it's not frozen? |
From what I've seen the freeze is done explicitly by the developer at some moment, would be needed calculate it at the moment of the |
Codecov Report
@@ Coverage Diff @@
## master #2229 +/- ##
=======================================
Coverage 97.15% 97.15%
=======================================
Files 39 39
Lines 7899 7899
Branches 1369 1369
=======================================
Hits 7674 7674
Misses 100 100
Partials 125 125 Continue to review full report at Codecov.
|
aiohttp/_frozenlist.pyx
Outdated
@@ -18,6 +18,9 @@ cdef class FrozenList: | |||
if self.frozen: | |||
raise RuntimeError("Cannot modify frozen list.") | |||
|
|||
cdef object _fast_len(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is used only once, please inline it -- the speed should be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
You've raised two separate questions:
|
Yes, the cost of |
Thanks! |
What do these changes do?
Reduce the footprint of the
send()
method by a 10% when there areno receivers connected.
Before
After
Script used [1]
[1] https://gist.github.com/pfreixes/baea4ecc7b5380d534d60a8c1e8da32f
Are there changes in behavior for the user?
No
Checklist
changes
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.