matrix-org / matrix-org/matrix-rust-sdk

Performance of `Room.members`/`get_member` in large rooms is bad

Open
#1,979 16 comments 0 reactions 1 assignee Claimed by @Hywan View on GitHub
X-Needs-Rust
Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

On Element Android X and Element iOS X we've noticed that it takes a significant amount of time to get the list of members in a room. Eyeballing the network requests and UI, for a room with ~10k members there's an approximately 10-12 second delay between the HTTP request to get members returning, and the UI actually showing anything.

I initially thought this was due to the volume of FFI calls we were making, but I've done some hacky tracing and it seems like all the time is spent in `Room.members`. For the room with 10k members, it takes 30-50ms to get the userIDs for all members, then around 10 seconds in total to call `get_member` for each of those users.

Inside `get_member` nothing in particular stands out:

- `store.get_member_event` takes 2.5s in aggregate
- `store.get_presence_event` takes 1.7s
- `store.get_profile` takes 1.9s
- `store.get_users_with_display_name` (for the display name ambiguity check) takes 2.0s

There are a couple more bits that I didn't explicitly time, but based on the total time taken I'd imagine they are similar. (Someone with an actual profiler set up may be able to provide more insight here).

Steps to reproduce:

- Add tracing lines to the start and end of `Room.members`
- Build a version of EAX or EIX with the modified SDK
- Join the Element Android channel
- Open the room details screen and observe loading spinner on the member button
- Observe ~10s gap in between trace statements

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.