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 125Continue to review full report at Codecov.
|
aiohttp/_frozenlist.pyx
Outdated
| if self.frozen: | ||
| raise RuntimeError("Cannot modify frozen list.") | ||
|
|
||
| cdef object _fast_len(self): |
There was a problem hiding this comment.
The function is used only once, please inline it -- the speed should be the same.
|
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
changesfolder<issue_id>.<type>for example (588.bug)issue_idchange 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.