summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-09-21 14:52:21 +0100
committerErik Johnston <erik@matrix.org>2018-09-21 14:52:21 +0100
commit79eded1ae4f0d341918f5c58076f1e60cd400e8a (patch)
treeb214853f8a1b329d05439bc79351e465ab798e2e
parentNewsfile (diff)
downloadsynapse-79eded1ae4f0d341918f5c58076f1e60cd400e8a.tar.xz
Make ExpiringCache slightly more performant
-rw-r--r--synapse/util/caches/expiringcache.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py
index 921a9c5b29..48ca2d634d 100644
--- a/synapse/util/caches/expiringcache.py
+++ b/synapse/util/caches/expiringcache.py
@@ -16,6 +16,8 @@
 import logging
 from collections import OrderedDict
 
+from six import iteritems
+
 from synapse.metrics.background_process_metrics import run_as_background_process
 from synapse.util.caches import register_cache
 
@@ -127,7 +129,7 @@ class ExpiringCache(object):
 
         keys_to_delete = set()
 
-        for key, cache_entry in self._cache.items():
+        for key, cache_entry in iteritems(self._cache):
             if now - cache_entry.time > self._expiry_ms:
                 keys_to_delete.add(key)
 
@@ -149,6 +151,8 @@ class ExpiringCache(object):
 
 
 class _CacheEntry(object):
+    __slots__ = ["time", "value"]
+
     def __init__(self, time, value):
         self.time = time
         self.value = value