summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2022-01-27 10:54:27 +0000
committerGitHub <noreply@github.com>2022-01-27 10:54:27 +0000
commit57e4786e907c390502f4ec6fb915e24cf5124351 (patch)
treef6d6d055a732f105c9e1c8867b1ecf1abd18f2b4
parentFix some indentation inconsistencies in the sample config (modules) (#11838) (diff)
downloadsynapse-57e4786e907c390502f4ec6fb915e24cf5124351.tar.xz
Create singletons for `StateFilter.{all,none}()` (#11836)
No point recreating these for each call, since they are frozen
-rw-r--r--changelog.d/11836.misc1
-rw-r--r--synapse/storage/state.py14
2 files changed, 10 insertions, 5 deletions
diff --git a/changelog.d/11836.misc b/changelog.d/11836.misc
new file mode 100644
index 0000000000..be7e331c63
--- /dev/null
+++ b/changelog.d/11836.misc
@@ -0,0 +1 @@
+Minor performance improvement in room state lookup.
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index df8b2f1088..913448f0f9 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -74,21 +74,21 @@ class StateFilter:
 
     @staticmethod
     def all() -> "StateFilter":
-        """Creates a filter that fetches everything.
+        """Returns a filter that fetches everything.
 
         Returns:
-            The new state filter.
+            The state filter.
         """
-        return StateFilter(types=frozendict(), include_others=True)
+        return _ALL_STATE_FILTER
 
     @staticmethod
     def none() -> "StateFilter":
-        """Creates a filter that fetches nothing.
+        """Returns a filter that fetches nothing.
 
         Returns:
             The new state filter.
         """
-        return StateFilter(types=frozendict(), include_others=False)
+        return _NONE_STATE_FILTER
 
     @staticmethod
     def from_types(types: Iterable[Tuple[str, Optional[str]]]) -> "StateFilter":
@@ -527,6 +527,10 @@ class StateFilter:
         )
 
 
+_ALL_STATE_FILTER = StateFilter(types=frozendict(), include_others=True)
+_NONE_STATE_FILTER = StateFilter(types=frozendict(), include_others=False)
+
+
 class StateGroupStorage:
     """High level interface to fetching state for event."""