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

Optimize Pagination by Filtering Beacon Events

Open
#4,865 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

I am encountering performance issues during pagination with the /messages API in rooms, due to processing a large number of org.matrix.msc3489.beacon events. While encrypted rooms still need to process each beacon event, I propose using the not_types RoomEventFilter to speed up pagination in non-encrypted rooms.

Additionally, I'm looking for guidance on optimizing live location sharing to improve its scalability within the SDK. Any insights or alternative strategies would be greatly appreciated.

Example timeline, the spec needs to only render the two m.text items in the timeline:

m.text
org.matrix.msc3489.beacon
org.matrix.msc3489.beacon
...2,000 more org.matrix.msc3489.beacon
m.text

Proposed solutions:

  1. Modify the paginate function to accept an optional RoomEventFilter, allowing clients to specify a custom filter.
async fn paginate(
        &self,
        dir: Direction,
        num_events: UInt,
        room_event_filter: Option<RoomEventFilter>,
    ) 
  1. Automatically filter by default on MessageOptions
impl MessagesOptions {
    /// Creates `MessagesOptions` with the given direction.
    ///
    /// All other parameters will be defaulted.
    pub fn new(dir: Direction) -> Self {
        Self { from: None, to: None, dir, limit: uint!(10), filter: assign!(RoomEventFilter::default(), {
                not_types: Some(vec![MessageLikeEvent::Beacon.to_string()])
            }) }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with crates/matrix-sdk/src/event_cache/paginator.rs at paginate and crates/matrix-sdk/src/room/messages.rs around MessagesOptions::new. Read how RoomEventFilter is passed to pagination and how encrypted versus non-encrypted rooms process beacon events. Done should establish an agreed filtering approach and verify that /messages pagination avoids unnecessary beacon processing without breaking encrypted-room handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.