forked-synapse/synapse
Richard van der Hoff af2248f8bf
Optimise missing prev_event handling (#9601)
Background: When we receive incoming federation traffic, and notice that we are missing prev_events from 
the incoming traffic, first we do a `/get_missing_events` request, and then if we still have missing prev_events,
we set up new backwards-extremities. To do that, we need to make a `/state_ids` request to ask the remote
server for the state at those prev_events, and then we may need to then ask the remote server for any events
in that state which we don't already have, as well as the auth events for those missing state events, so that we
can auth them.

This PR attempts to optimise the processing of that state request. The `state_ids` API returns a list of the state
events, as well as a list of all the auth events for *all* of those state events. The optimisation comes from the
observation that we are currently loading all of those auth events into memory at the start of the operation, but
we almost certainly aren't going to need *all* of the auth events. Rather, we can check that we have them, and
leave the actual load into memory for later. (Ideally the federation API would tell us which auth events we're
actually going to need, but it doesn't.)

The effect of this is to reduce the number of events that I need to load for an event in Matrix HQ from about
60000 to about 22000, which means it can stay in my in-memory cache, whereas previously the sheer number
of events meant that all 60K events had to be loaded from db for each request, due to the amount of cache
churn. (NB I've already tripled the size of the cache from its default of 10K).

Unfortunately I've ended up basically C&Ping `_get_state_for_room` and `_get_events_from_store_or_dest` into
a new method, because `_get_state_for_room` is also called during backfill, which expects the auth events to be
returned, so the same tricks don't work. That said, I don't really know why that codepath is completely different
(ultimately we're doing the same thing in setting up a new backwards extremity) so I've left a TODO suggesting
that we clean it up.
2021-03-15 13:51:02 +00:00
..
_scripts Strip trailing / from server_url in register_new_matrix_user (#8823) 2020-11-26 10:57:26 +00:00
api Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
app Set X-Forwarded-Proto header when frontend-proxy proxies a request (#9539) 2021-03-03 18:49:08 +00:00
appservice Add ResponseCache tests. (#9458) 2021-03-08 14:00:07 -05:00
config JWT OIDC secrets for Sign in with Apple (#9549) 2021-03-09 15:03:37 +00:00
crypto Cache config options in SSL verification (#9255) 2021-01-28 17:38:59 +00:00
events Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
federation Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
groups Add type hints to groups code. (#9393) 2021-02-17 08:41:47 -05:00
handlers Optimise missing prev_event handling (#9601) 2021-03-15 13:51:02 +00:00
http Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
logging Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
metrics Fix additional type hints from Twisted upgrade. (#9518) 2021-03-03 15:47:38 -05:00
module_api Record the SSO Auth Provider in the login token (#9510) 2021-03-04 14:44:22 +00:00
push Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
replication Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
res/templates Support not providing an IdP icon when choosing a username. (#9440) 2021-02-19 07:48:46 -05:00
rest Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
server_notices Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
spam_checker_api Combine SpamCheckerApi with the more generic ModuleApi. (#8464) 2020-10-07 12:03:26 +01:00
state Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
static Add initial support for a "pick your IdP" page (#9017) 2021-01-05 11:25:28 +00:00
storage Optimise missing prev_event handling (#9601) 2021-03-15 13:51:02 +00:00
streams Make token serializing/deserializing async (#8427) 2020-09-30 20:29:19 +01:00
util Add logging to ObservableDeferred callbacks (#9523) 2021-03-09 11:09:31 +00:00
__init__.py 1.29.0 2021-03-08 13:52:13 +00:00
event_auth.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
notifier.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
python_dependencies.py Add a comment about systemd-python. (#9464) 2021-02-23 13:42:36 +00:00
secrets.py Stop sub-classing object (#8249) 2020-09-04 06:54:56 -04:00
server.py Fix additional type hints from Twisted 21.2.0. (#9591) 2021-03-12 11:37:57 -05:00
types.py Convert Requester to attrs (#9586) 2021-03-10 18:15:56 +00:00
visibility.py Merge pull request #9150 from Yoric/develop-context 2021-02-08 15:53:44 +01:00