synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Slow sliding sync when connection metadata gets large

Open erikjohnston opened this issue 1 month ago • 1 comments

We track what state we have sent down in a room in the sliding_sync_connection_required_state table. We then pull this data out for all rooms at the start of every sync. For long lived connections this can return a lot of data and take a long time.

Instead, we should only pull out this for rooms when we've calculated which rooms have updates to send down sync.

erikjohnston avatar Nov 13 '25 11:11 erikjohnston

Actually, this is a bit more complicated than initially thought. The way we store the required_state room config in the DB is to deduplicate each actual required_state, i.e. the DB looks like room_id -> required_state_id -> required_state. This makes sense when the client will typically use the same required_state for the majority of rooms.

However, the lazy loaded membership implementation is done by recording in that table which users we have sent down already (e.g. additional ["m.room.member", "@bob"] entries). This means that actually each room ends up with very different states per room.

We should instead separate out the tracking of lazy loaded members into a separate table. That way sliding_sync_connection_required_state will be reduced a lot, and so we don't need to do any refactoring of when we read/record to that table

erikjohnston avatar Nov 13 '25 13:11 erikjohnston