From f666d6f5d71b34762afc6c3d987496633ff2182c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 25 Oct 2019 10:28:36 +0100 Subject: [PATCH 1/3] Remove repeated calls to config.stats_enabled. Turns out that fetching variables from the config object is expensive, so doing it once at startup avoids unnecessary work. --- synapse/handlers/stats.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py index 466daf9202a7..26bc2766920a 100644 --- a/synapse/handlers/stats.py +++ b/synapse/handlers/stats.py @@ -45,6 +45,8 @@ def __init__(self, hs): self.is_mine_id = hs.is_mine_id self.stats_bucket_size = hs.config.stats_bucket_size + self.stats_enabled = hs.config.stats_enabled + # The current position in the current_state_delta stream self.pos = None @@ -61,7 +63,7 @@ def __init__(self, hs): def notify_new_event(self): """Called when there may be more deltas to process """ - if not self.hs.config.stats_enabled or self._is_processing: + if not self.stats_enabled or self._is_processing: return self._is_processing = True From a52b23d413b9e64c36b519c27b057a41de5d9dd4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 25 Oct 2019 10:34:10 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/6255.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6255.misc diff --git a/changelog.d/6255.misc b/changelog.d/6255.misc new file mode 100644 index 000000000000..45bc493648b5 --- /dev/null +++ b/changelog.d/6255.misc @@ -0,0 +1 @@ +Small performance improvement by removing repeated config lookups in room stats calculation. From 7e7a1461f64888fa71c8f06fb12f29cc3d233179 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 25 Oct 2019 10:57:37 +0100 Subject: [PATCH 3/3] Fix tests --- tests/handlers/test_stats.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/handlers/test_stats.py b/tests/handlers/test_stats.py index d5c8bd7612af..e0075ccd328b 100644 --- a/tests/handlers/test_stats.py +++ b/tests/handlers/test_stats.py @@ -607,6 +607,7 @@ def test_initial_background_update(self): """ self.hs.config.stats_enabled = False + self.handler.stats_enabled = False u1 = self.register_user("u1", "pass") u1token = self.login("u1", "pass") @@ -618,6 +619,7 @@ def test_initial_background_update(self): self.assertIsNone(self._get_current_stats("user", u1)) self.hs.config.stats_enabled = True + self.handler.stats_enabled = True self._perform_background_initial_update()