Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf of sync device lists #17191

Merged
merged 2 commits into from
May 14, 2024
Merged

Conversation

erikjohnston
Copy link
Member

It's almost always more efficient to query the rooms that have device list changes, rather than looking at the list of all users whose devices have changed and then look for shared rooms.

It's almost always more efficient to query the rooms that have device
list changes, rather than looking at the list of all users whose devices
have changed and then look for shared rooms.
@erikjohnston erikjohnston marked this pull request as ready for review May 14, 2024 10:39
@erikjohnston erikjohnston requested a review from a team as a code owner May 14, 2024 10:39
@@ -1475,7 +1462,7 @@ async def get_device_list_changes_in_rooms(

sql = """
SELECT DISTINCT user_id FROM device_lists_changes_in_room
WHERE {clause} AND stream_id >= ?
WHERE {clause} AND stream_id > ?
Copy link
Member Author

@erikjohnston erikjohnston May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a bug that we didn't catch as we didn't test this code path much. I don't think its much of a problem, we'll just keep sending down the same device list repeatedly until the stream ID increments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks plausible, and nice to see the reduction in code size as well.

Hopefully at least some tests cover this code path...

@@ -1475,7 +1462,7 @@ async def get_device_list_changes_in_rooms(

sql = """
SELECT DISTINCT user_id FROM device_lists_changes_in_room
WHERE {clause} AND stream_id >= ?
WHERE {clause} AND stream_id > ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@erikjohnston
Copy link
Member Author

Hopefully at least some tests cover this code path...

Yeah, we do have quite a few tests for device lists, which should now all test this code path (rather than the other one...)

@erikjohnston erikjohnston merged commit 0b91ccc into develop May 14, 2024
38 checks passed
@erikjohnston erikjohnston deleted the erikj/faster_sync_devices branch May 14, 2024 13:39
erikjohnston added a commit that referenced this pull request May 16, 2024
erikjohnston added a commit that referenced this pull request May 16, 2024
erikjohnston added a commit that referenced this pull request May 18, 2024
It's almost always more efficient to query the rooms that have device
list changes, rather than looking at the list of all users whose devices
have changed and then look for shared rooms.
erikjohnston added a commit that referenced this pull request May 21, 2024
Re-introduces #17191, and includes #17197 and #17214

The basic idea is to stop calling `get_rooms_for_user` everywhere, and
instead use the table `device_lists_changes_in_room`.

Commits reviewable one-by-one.
Mic92 pushed a commit to Mic92/synapse that referenced this pull request Jun 14, 2024
Re-introduces element-hq#17191, and includes element-hq#17197 and element-hq#17214

The basic idea is to stop calling `get_rooms_for_user` everywhere, and
instead use the table `device_lists_changes_in_room`.

Commits reviewable one-by-one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants