MatrixSynapse/synapse
Erik Johnston 707d5e4e48
Encode JSON responses on a thread in C, mk2 (#10905)
Currently we use `JsonEncoder.iterencode` to write JSON responses, which ensures that we don't block the main reactor thread when encoding huge objects. The downside to this is that `iterencode` falls back to using a pure Python encoder that is *much* less efficient and can easily burn a lot of CPU for huge responses. To fix this, while still ensuring we don't block the reactor loop, we encode the JSON on a threadpool using the standard `JsonEncoder.encode` functions, which is backed by a C library.

Doing so, however, requires `respond_with_json` to have access to the reactor, which it previously didn't. There are two ways of doing this:

1. threading through the reactor object, which is a bit fiddly as e.g. `DirectServeJsonResource` doesn't currently take a reactor, but is exposed to modules and so is a PITA to change; or
2. expose the reactor in `SynapseRequest`, which requires updating a bunch of servlet types.

I went with the latter as that is just a mechanical change, and I think makes sense as a request already has a reactor associated with it (via its http channel).
2021-09-28 09:37:58 +00:00
..
_scripts
api
app
appservice
config Fix race conditions when creating media store and config directories (#10913) 2021-09-27 11:29:23 +01:00
crypto
events Add a spamchecker callback to allow or deny room creation based on invites (#10898) 2021-09-24 16:38:23 +02:00
federation
groups
handlers Add a spamchecker callback to allow or deny room creation based on invites (#10898) 2021-09-24 16:38:23 +02:00
http Encode JSON responses on a thread in C, mk2 (#10905) 2021-09-28 09:37:58 +00:00
logging
metrics
module_api
push Encode JSON responses on a thread in C, mk2 (#10905) 2021-09-28 09:37:58 +00:00
replication
res
rest Avoid storing URL cache files in storage providers (#10911) 2021-09-27 12:55:27 +01:00
server_notices
spam_checker_api
state
static
storage Document changes to schema version 61 - 64 (#10917) 2021-09-24 17:09:12 -05:00
streams
util Encode JSON responses on a thread in C, mk2 (#10905) 2021-09-28 09:37:58 +00:00
__init__.py
event_auth.py
notifier.py
python_dependencies.py
server.py
types.py
visibility.py