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

[meta] Event Cache should directly be integrated inside the sync response flow

Open
#5,500 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Right now, when a sync response is received, it goes in the sync response flow. It starts at Client::receive_sync_response. At the end, it emits a RoomUpdates on a broadcast channel. On the other side of this channel, EventCache is listening.

Why this decoupled design? If the Event Cache is slow, it's not blocking the sync response, so the whole sync loop (!).

It brings some disadvantages though:

  • When an error happens in the Event Cache, it's harder to trace it to the sync response
    • It means we can't “retry” a sync iteration, or do something “proper” with the sync data
  • When Event Cache has performance issues (it happened recently due to regressions), we don't see it immediately because it runs in parallel, and it's harder to correctly connect them to the real reasons
  • It takes more memory, so more energy, than it should:
    • Everything that goes in a channel must be cloned, so all events are duplicated

Proposal:

  • Event Cache is plugged directly inside the sync response flow
    • We can apply the updates on the Event Cache with a parallel iterator per room (hello rayon) to tackle the performance constraint (if the multiple locks allow that, we need to investigate that anyway)
    • We can remove the EventCache::listen_task
      • One less task!
      • Less states in case of channel has lagged or is closed
  • Remove this channel

Advantages:

  • Event cache errors can bubble up to the sync response flow
  • We can decide to retry a sync if we detect an error
  • It saves memory, so energy
  • No magic. Straightforward and trivial flow!

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 at Client::receive_sync_response and trace the RoomUpdates broadcast channel to EventCache::listen_task. Investigate how per-room parallel updates with rayon would interact with locking, then remove the channel and listener once Event Cache errors can propagate through the sync response flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.