This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Fetch less state when we _compute_event_context_with_maybe_missing_prevs
#15616
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fetch less state when we
_compute_event_context_with_maybe_missing_prevs
Part of making
/messages
faster: #13356Background
When we have to
_compute_event_context_with_maybe_missing_prevs
,_get_state_groups_from_groups
currently takes up most of the time. It makes the following recursive query for each state group given which goes up the entire state_group chain and returns the complete distinct state which means thousands of membership events at the very least. For example, with a random/messages
request in the Matrix HQ room we did 10x of these queries which each took 0.5-2 seconds and return roughly 88k events every time totaling 14s.https://explain.depesz.com/s/OuOe
https://explain.dalibo.com/plan/ef6bc290f2dced17
EXPLAIN ANAYLZE
query outputFull Jaeger trace JSON
Questions/ideas
Do we really need all of this state?
Can we get away with adding a
state_filter
that only fetches the auth event types out?StateFilter.from_types(event_auth.auth_types_for_event(event.room_version, event))
Or maybe we can avoid fetching all
m.room.member
events except for the one that pertains to the eventsender
?Another idea, since we fetch state for many
state_groups
, can we re-use the work from one to the other? Perhaps we can have one recursive query starting at the maxstate_group
given and somehow assembles what we want for each of the subsequent state groups.For reference, we previously optimized the SQL query in
filter_events_for_client
->_get_state_groups_from_groups
in #14527 but that was a case where we already had astate_filter
to only grab them.room.history_visibility
andm.room.member
events.Dev notes
Grabbing all of the state via
_get_state_groups_from_groups
is the slowest part of_compute_event_context_with_maybe_missing_prevs
_compute_event_context_with_maybe_missing_prevs
_get_state_groups_from_groups
🐢Of all the state we grab in
_compute_event_context_with_maybe_missing_prevs
, we only ever use TODO_process_pulled_event
_compute_event_context_with_maybe_missing_prevs
_process_received_pdu
_check_event_auth
_state_resolution_handler.resolve_events_with_store(...)
event_auth.auth_types_for_event(event.room_version, event)
) 🎈_check_for_soft_fail
-> Looks for auth events again 🎈
_run_push_actions_and_persist_event
-> Looks for
m.room.power_levels
🎈filter_event_for_clients_with_state
->
EventTypes.RoomHistoryVisibility
🎈Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)