From 592cfd14016fc8833efd587dc69e9e521b2d3233 Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Sun, 27 Aug 2017 22:00:07 +0200 Subject: [PATCH 1/4] Speed up Signals when there are no receivers. Reduce the footprint of the `send()` method by a 10% when there are no receivers connected. --- aiohttp/_frozenlist.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aiohttp/_frozenlist.pyx b/aiohttp/_frozenlist.pyx index 29e81d1d66f..745cd19ed5f 100644 --- a/aiohttp/_frozenlist.pyx +++ b/aiohttp/_frozenlist.pyx @@ -4,9 +4,11 @@ from collections.abc import MutableSequence cdef class FrozenList: cdef readonly bint frozen + cdef readonly bint _receivers cdef list _items def __init__(self, items=None): + self._receivers = False self.frozen = False if items is not None: items = list(items) @@ -18,6 +20,9 @@ cdef class FrozenList: if self.frozen: raise RuntimeError("Cannot modify frozen list.") + cdef object _fast_len(self): + return len(self._items) + def freeze(self): self.frozen = True @@ -33,7 +38,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__() From 46e2fcb342f1ae81ddb3b48e52ccabe6dcd322eb Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Sun, 27 Aug 2017 22:14:07 +0200 Subject: [PATCH 2/4] Added change file --- changes/2229.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/2229.feature diff --git a/changes/2229.feature b/changes/2229.feature new file mode 100644 index 00000000000..e6945c13e6f --- /dev/null +++ b/changes/2229.feature @@ -0,0 +1 @@ +Speed up Signals when there are no receivers From 98f671aafd51f9ed9e3fdcf55d4eb0c07fd29013 Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Sun, 27 Aug 2017 22:15:50 +0200 Subject: [PATCH 3/4] Removed invalid attributes --- aiohttp/_frozenlist.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/aiohttp/_frozenlist.pyx b/aiohttp/_frozenlist.pyx index 745cd19ed5f..c1caba72ad2 100644 --- a/aiohttp/_frozenlist.pyx +++ b/aiohttp/_frozenlist.pyx @@ -4,11 +4,9 @@ from collections.abc import MutableSequence cdef class FrozenList: cdef readonly bint frozen - cdef readonly bint _receivers cdef list _items def __init__(self, items=None): - self._receivers = False self.frozen = False if items is not None: items = list(items) From cc3eb8df2ea1b7c1895de28eef6f0da85338d66c Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Mon, 28 Aug 2017 09:05:17 +0200 Subject: [PATCH 4/4] Make the _fast_len inline --- aiohttp/_frozenlist.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/_frozenlist.pyx b/aiohttp/_frozenlist.pyx index c1caba72ad2..b1305772f4b 100644 --- a/aiohttp/_frozenlist.pyx +++ b/aiohttp/_frozenlist.pyx @@ -18,7 +18,7 @@ cdef class FrozenList: if self.frozen: raise RuntimeError("Cannot modify frozen list.") - cdef object _fast_len(self): + cdef inline object _fast_len(self): return len(self._items) def freeze(self):