-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optimisation to
StreamChangeCache
(#17130)
When there have been lots of changes compared with the number of entities, we can do a fast(er) path. Locally I ran some benchmarking, and the comparison seems to give the best determination of which method we use.
- Loading branch information
1 parent
7c9ac01
commit 3e6ee8f
Showing
3 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add optimisation to `StreamChangeCache.get_entities_changed(..)`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from parameterized import parameterized | ||
|
||
from synapse.util.caches.stream_change_cache import StreamChangeCache | ||
|
||
from tests import unittest | ||
|
@@ -161,7 +163,8 @@ def test_has_any_entity_changed(self) -> None: | |
self.assertFalse(cache.has_any_entity_changed(2)) | ||
self.assertFalse(cache.has_any_entity_changed(3)) | ||
|
||
def test_get_entities_changed(self) -> None: | ||
@parameterized.expand([(0,), (1000000000,)]) | ||
def test_get_entities_changed(self, perf_factor: int) -> None: | ||
""" | ||
StreamChangeCache.get_entities_changed will return the entities in the | ||
given list that have changed since the provided stream ID. If the | ||
|
@@ -178,7 +181,9 @@ def test_get_entities_changed(self) -> None: | |
# get the ones after that point. | ||
self.assertEqual( | ||
cache.get_entities_changed( | ||
["[email protected]", "[email protected]", "[email protected]"], stream_pos=2 | ||
["[email protected]", "[email protected]", "[email protected]"], | ||
stream_pos=2, | ||
_perf_factor=perf_factor, | ||
), | ||
{"[email protected]", "[email protected]"}, | ||
) | ||
|
@@ -195,6 +200,7 @@ def test_get_entities_changed(self) -> None: | |
"[email protected]", | ||
], | ||
stream_pos=2, | ||
_perf_factor=perf_factor, | ||
), | ||
{"[email protected]", "[email protected]"}, | ||
) | ||
|
@@ -210,14 +216,19 @@ def test_get_entities_changed(self) -> None: | |
"[email protected]", | ||
], | ||
stream_pos=0, | ||
_perf_factor=perf_factor, | ||
), | ||
{"[email protected]", "[email protected]", "[email protected]", "[email protected]"}, | ||
) | ||
|
||
# Query a subset of the entries mid-way through the stream. We should | ||
# only get back the subset. | ||
self.assertEqual( | ||
cache.get_entities_changed(["[email protected]"], stream_pos=2), | ||
cache.get_entities_changed( | ||
["[email protected]"], | ||
stream_pos=2, | ||
_perf_factor=perf_factor, | ||
), | ||
{"[email protected]"}, | ||
) | ||
|
||
|