Skip to content

event_cache: add SpecificEventsCache for caller-supplied event IDs - #6877

Open
alexookah wants to merge 8 commits into
matrix-org:mainfrom
alexookah:specific-events-cache
Open

alexookah wants to merge 8 commits into
matrix-org:mainfrom
alexookah:specific-events-cache

Conversation

@alexookah

@alexookah alexookah commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

First event-cache step for #6876. SpecificEventsCache is the pinned-events approach with the id list supplied by the caller instead of coming from m.room.pinned_events.

  • load: each id with its reactions and edits, through the same loader as pinned events (now shared), sorted chronologically
  • sync: reuses aggregate_timeline_for_pinned_events with the cache's current ids, so reactions, edits and redactions of what it holds reach it
  • set_event_ids(): diffs the set and reloads if it changed; a set that can't be loaded at all is an error and the previous set is kept
  • in-memory only, like the event-focused cache; it doesn't paginate, callers grow the set
  • lifetime: the room's caches hold these caches weakly. Once the caller drops its handles, the next sync forgets the cache and its state

Six commits: the loader refactor, the state and how it follows sync, the cache handle, the wiring into the room caches, the tests, and the weak handles.

A store clear leaves these caches alone on purpose: nothing of theirs lives in the store, and sync keeps them current.

No timeline or FFI yet.

@codecov

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.86998% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (7604d4f) to head (89efd49).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...-sdk/src/event_cache/caches/specific_events/mod.rs 81.03% 27 Missing and 17 partials ⚠️
crates/matrix-sdk/src/event_cache/caches/mod.rs 80.95% 1 Missing and 11 partials ⚠️
...tes/matrix-sdk/src/event_cache/states/selectors.rs 83.87% 4 Missing and 1 partial ⚠️
crates/matrix-sdk/src/event_cache/redecryptor.rs 94.11% 0 Missing and 2 partials ⚠️
crates/matrix-sdk/src/event_cache/mod.rs 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6877      +/-   ##
==========================================
- Coverage   90.30%   90.27%   -0.04%     
==========================================
  Files         414      415       +1     
  Lines      120232   120616     +384     
  Branches   120232   120616     +384     
==========================================
+ Hits       108576   108882     +306     
- Misses       7579     7620      +41     
- Partials     4077     4114      +37     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed

codspeed Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 50.2%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 49 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ Restore session [memory store] 236.2 ms 474.3 ms -50.2%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing alexookah:specific-events-cache (89efd49) with main (7604d4f)

Open in CodSpeed

@alexookah
alexookah force-pushed the specific-events-cache branch 3 times, most recently from 6ce3fc2 to 6eb7db7 Compare August 31, 2026 16:45
@alexookah

Copy link
Copy Markdown
Contributor Author

@Hywan
Could you have a look at this PR as well? Just some feedback would be really appreciated.

@alexookah
alexookah force-pushed the specific-events-cache branch 2 times, most recently from 32b5377 to 403542f Compare September 4, 2026 12:43
@alexookah

alexookah commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello @Hywan
I rebased on main, split into 5 small commits and added tests. The tests caught a deadlock on first use, fixed, and the loader is now shared with the pinned-events cache.
Would appreciate your view on this whenever you have a moment. No rush
Thank you

Move the loading of events with their reactions and edits out of
PinnedEventsCache into a function that other caches can use, and skip an
event that is both requested and a relation of another one. No behaviour
change for pinned events.
The state of a cache for a caller-supplied set of event IDs: the ids, a
linked chunk holding the events and their relations, and the handling of
sync events related to them (dedup against loaded relations, append the
rest, apply redactions). It lives in the event cache's state map under a
per-instance selector, so several such caches can coexist for one room.
In-memory only: nothing is written to the store.
The handle over that state: create it for a set of ids, load the events
with their reactions and edits through the shared loader, read or
subscribe to them, and replace the set with set_event_ids(), which
reloads when it changed and keeps the previous set if nothing could be
loaded. Loading never holds the state lock, since it goes through the
event cache, which needs it too.
…yption

RoomEventCache creates the caches on demand and forwards them the sync
timeline filtered to their events, EventCache exposes them, and the
redecryptor resolves their in-memory UTDs, like for the other caches
that live only in memory. The initial load happens once the room caches'
guard is released.
Loading a set with its relations in chronological order and without
duplicates, skipping ids that can't be loaded and failing when none can,
sync updates reaching the cache (reactions, edits, redactions of the
events and of their relations) while unrelated events don't,
set_event_ids being a no-op for the same set, reloading when it grows or
shrinks and keeping the previous set on failure, and the not-subscribed
error.
@alexookah
alexookah force-pushed the specific-events-cache branch from 403542f to a5f5499 Compare September 8, 2026 21:57
@alexookah
alexookah marked this pull request as ready for review September 15, 2026 12:54
@alexookah
alexookah requested a review from a team as a code owner September 15, 2026 12:54
@alexookah
alexookah requested review from Hywan and removed request for a team September 15, 2026 12:54
…into specific-events-cache

# Conflicts:
#	crates/matrix-sdk/src/event_cache/caches/mod.rs
#	crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs
@alexookah

alexookah commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @Hywan, I brought this up to date with main and added a few tests.
Could you take a quick look when you get a chance, even just to tell me if it's worth continuing?
@stefanceriu, if you have some time, I'd love your eyes on it too.
Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant