matrix-org / matrix-org/matrix-rust-sdk
perf(sdk): One lock per room for the `EventCacheStore` in the Event Cache
@Hywan is already working on this.
Since Nov 12, 2025.
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 500
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 106
Description
Right now, there is the `EventCacheStore`. To access it, we have an `EventCacheStoreLock`. It's all good, no problem with that, it's a cross-process lock, all fine. Except that it's not really optimal as each `RoomEventCache` holds a clone of the same `EventCacheStoreLock`, which means that each room in the Event Cache uses the same lock over _all the rooms_ of the store. It blocks the possibility to handle updates for each room in parallel (I guess that's why https://github.com/matrix-org/matrix-rust-sdk/pull/5426 didn't provide the expected results).
A simple approach would be to derive a particular key for the cross-process lock, like adding a suffix of the form `-event-cache-room-{room_id}` or something like that. That way, we will have one cross-process lock per room. We can create a `RoomEventCacheStoreLock` type that will use this new key. See here:
https://github.com/matrix-org/matrix-rust-sdk/blob/a3424a7c4a8f8b1c0deeecfc69a3ff2bc3135765/crates/matrix-sdk-base/src/event_cache/store/mod.rs#L76-L80
---
* Part of https://github.com/matrix-org/matrix-rust-sdk/issues/5554
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.