Skip to content

Commit

Permalink
Speed up Signals when there are no receivers. (#2229)
Browse files Browse the repository at this point in the history
* Speed up Signals when there are no receivers.

Reduce the footprint of the `send()` method by a 10% when there are
no receivers connected.

* Added change file

* Removed invalid attributes

* Make the _fast_len inline
  • Loading branch information
pfreixes authored and asvetlov committed Aug 28, 2017
1 parent d7658d4 commit d2236cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aiohttp/_frozenlist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ cdef class FrozenList:
if self.frozen:
raise RuntimeError("Cannot modify frozen list.")

cdef inline object _fast_len(self):
return len(self._items)

def freeze(self):
self.frozen = True

Expand All @@ -33,7 +36,7 @@ cdef class FrozenList:
del self._items[index]

def __len__(self):
return self._items.__len__()
return self._fast_len()

def __iter__(self):
return self._items.__iter__()
Expand Down
1 change: 1 addition & 0 deletions changes/2229.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up Signals when there are no receivers

0 comments on commit d2236cf

Please sign in to comment.