element-hq / element-hq/synapse

Initial `/sync` when filtered to a single room can be very slow

Open
#10,842 0 comments 0 reactions 0 assignees View on GitHub
P3 S-Minor T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#10842](https://github.com/matrix-org/synapse/issues/10842).

---

### Description

The `/rooms/{roomId}/initialSync` endpoint is deprecated and the [documentation](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0roomsroomidinitialsync) suggests using `/sync` instead.

However, using `/sync` with a room filter has drastically worse performance for users in very many rooms,
eg. taking up to 400 seconds for a user in 2,200 rooms and pulling 100,000+ events from the database.

### Steps to reproduce

```
GET /_matrix/client/r0/sync?filter=%7B%22room%22:+%7B%22rooms%22:+%5B%22!XXXXXXXXXXXXXXXXXX:matrix.org%22%5D,+%22state%22:+%7B%22rooms%22:+%5B%22!XXXXXXXXXXXXXXXXXX:matrix.org%22%5D%7D,+%22timeline%22:+%7B%22rooms%22:+%5B%22!XXXXXXXXXXXXXXXXXX:matrix.org%22%5D,+%22senders%22:+%5B%22@xxxxxxxxxx:matrix.org%22%5D%7D,+%22ephemeral%22:+%7B%22limit%22:+0,+%22types%22:+%5B%5D%7D,+%22account_data%22:+%7B%22limit%22:+0,+%22types%22:+%5B%5D%7D%7D,+%22presence%22:+%7B%22limit%22:+0,+%22types%22:+%5B%5D%7D,+%22account_data%22:+%7B%22limit%22:+0,+%22types%22:+%5B%5D%7D%7D
```

### Version information

- **Homeserver**: matrix.org

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the filtered GET /_matrix/client/r0/sync request described in the issue and profile the initial-sync path that handles it. Trace why a single-room filter reads 100,000+ events for users in many rooms; done means the filtered initial /sync no longer exhibits the reported excessive latency and database reads.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.