Small performance improvements for sliding sync (#17672)

A couple of small performance improvements for sliding sync.
This commit is contained in:
Erik Johnston 2024-09-06 11:44:13 +01:00 committed by GitHub
parent 786de8570b
commit a708e1afd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 17 deletions

1
changelog.d/17672.misc Normal file
View File

@ -0,0 +1 @@
Small performance improvement in speeding up sliding sync.

View File

@ -350,13 +350,18 @@ class SlidingSyncRoomLists:
all_rooms.update(filtered_sync_room_map) all_rooms.update(filtered_sync_room_map)
# Sort the list
sorted_room_info = await self.sort_rooms_using_tables(
filtered_sync_room_map, to_token
)
ops: List[SlidingSyncResult.SlidingWindowList.Operation] = [] ops: List[SlidingSyncResult.SlidingWindowList.Operation] = []
if list_config.ranges: if list_config.ranges:
if list_config.ranges == [(0, len(filtered_sync_room_map) - 1)]:
# If we are asking for the full range, we don't need to sort the list.
sorted_room_info = list(filtered_sync_room_map.values())
else:
# Sort the list
sorted_room_info = await self.sort_rooms_using_tables(
filtered_sync_room_map, to_token
)
for range in list_config.ranges: for range in list_config.ranges:
room_ids_in_list: List[str] = [] room_ids_in_list: List[str] = []

View File

@ -19,6 +19,7 @@ from enum import Enum
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
AbstractSet, AbstractSet,
Any,
Callable, Callable,
Dict, Dict,
Final, Final,
@ -703,7 +704,12 @@ class HaveSentRoom(Generic[T]):
@staticmethod @staticmethod
def never() -> "HaveSentRoom[T]": def never() -> "HaveSentRoom[T]":
return HaveSentRoom(HaveSentRoomFlag.NEVER, None) # We use a singleton to avoid repeatedly instantiating new `never`
# values.
return _HAVE_SENT_ROOM_NEVER
_HAVE_SENT_ROOM_NEVER: HaveSentRoom[Any] = HaveSentRoom(HaveSentRoomFlag.NEVER, None)
@attr.s(auto_attribs=True, slots=True, frozen=True) @attr.s(auto_attribs=True, slots=True, frozen=True)

View File

@ -588,19 +588,16 @@ class SlidingSyncRoomsMetaTestCase(SlidingSyncBase):
) )
# Make sure the list includes the rooms in the right order # Make sure the list includes the rooms in the right order
self.assertListEqual( self.assertEqual(
list(response_body["lists"]["foo-list"]["ops"]), len(response_body["lists"]["foo-list"]["ops"]),
[ 1,
{
"op": "SYNC",
"range": [0, 1],
# room1 sorts before room2 because it has the latest event (the
# reaction)
"room_ids": [room_id1, room_id2],
}
],
response_body["lists"]["foo-list"], response_body["lists"]["foo-list"],
) )
op = response_body["lists"]["foo-list"]["ops"][0]
self.assertEqual(op["op"], "SYNC")
self.assertEqual(op["range"], [0, 1])
# Note that we don't order the ops anymore, so we need to compare sets.
self.assertIncludes(set(op["room_ids"]), {room_id1, room_id2}, exact=True)
# The `bump_stamp` for room1 should point at the latest message (not the # The `bump_stamp` for room1 should point at the latest message (not the
# reaction since it's not one of the `DEFAULT_BUMP_EVENT_TYPES`) # reaction since it's not one of the `DEFAULT_BUMP_EVENT_TYPES`)