synapse/synapse/http
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
..
federation Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
__init__.py Use inline type hints in various other places (in synapse/) (#10380) 2021-07-15 11:02:43 +01:00
additional_resource.py Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
client.py Use direct references for some configuration variables (part 2) (#10812) 2021-09-15 08:34:52 -04:00
connectproxyclient.py support federation queries through http connect proxy (#10475) 2021-08-11 15:34:59 +01:00
matrixfederationclient.py Use direct references for configuration variables (part 4). (#10893) 2021-09-23 12:03:01 -04:00
proxyagent.py Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
request_metrics.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
server.py Encode JSON responses on a thread in C, mk2 (#10905) 2021-09-28 09:37:58 +00:00
servlet.py Additional type hints for client REST servlets (part 5) (#10736) 2021-09-03 09:22:22 -04:00
site.py Add reactor to SynapseRequest and fix up types. (#10868) 2021-09-24 11:01:25 +01:00