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.