Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 157fc20

Browse filesBrowse files
nallathjstasiak
authored andcommitted
Significantly improve the speed of the entries function of the cache
Tested this with Python 3.6.8, Fedora 28. This was done in a network with a lot of discoverable devices. before: Total time: 1.43086 s Line # Hits Time Per Hit % Time Line Contents ============================================================== 1138 @Profile 1139 def entries(self): 1140 """Returns a list of all entries""" 1141 2063 3578.0 1.7 0.3 if not self.cache: 1142 2 3.0 1.5 0.0 return [] 1143 else: 1144 # avoid size change during iteration by copying the cache 1145 2061 22051.0 10.7 1.5 values = list(self.cache.values()) 1146 2061 1405227.0 681.8 98.2 return reduce(lambda a, b: a + b, values) After: Total time: 0.43725 s Line # Hits Time Per Hit % Time Line Contents ============================================================== 1138 @Profile 1139 def entries(self): 1140 """Returns a list of all entries""" 1141 3651 10171.0 2.8 2.3 if not self.cache: 1142 2 7.0 3.5 0.0 return [] 1143 else: 1144 # avoid size change during iteration by copying the cache 1145 3649 67054.0 18.4 15.3 values = list(self.cache.values()) 1146 3649 360018.0 98.7 82.3 return list(itertools.chain.from_iterable(values))
1 parent 6ab7dbf commit 157fc20
Copy full SHA for 157fc20

File tree

1 file changed

+2
-2
lines changed
Filter options

1 file changed

+2
-2
lines changed

‎zeroconf/__init__.py

Copy file name to clipboardExpand all lines: zeroconf/__init__.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import enum
2424
import errno
2525
import ipaddress
26+
import itertools
2627
import logging
2728
import os
2829
import re
@@ -33,7 +34,6 @@
3334
import threading
3435
import time
3536
import warnings
36-
from functools import reduce
3737
from typing import AnyStr, Dict, List, Optional, Sequence, Union, cast
3838
from typing import Any, Callable, Set, Tuple # noqa # used in type hints
3939

@@ -1142,7 +1142,7 @@ def entries(self):
11421142
else:
11431143
# avoid size change during iteration by copying the cache
11441144
values = list(self.cache.values())
1145-
return reduce(lambda a, b: a + b, values)
1145+
return list(itertools.chain.from_iterable(values))
11461146

11471147

11481148
class Engine(threading.Thread):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.