synapse-product/synapse/util
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
..
caches Opt out of cache expiry for get_users_who_share_room_with_user (#10826) 2021-09-22 14:21:58 +01:00
__init__.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
async_helpers.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
batching_queue.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
daemonize.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
distributor.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
file_consumer.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
frozenutils.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
hash.py Add missing type hints to synapse.util (#9982) 2021-05-24 15:32:01 -04:00
httpresourcetree.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
iterutils.py Encode JSON responses on a thread in C, mk2 (#10905) 2021-09-28 09:37:58 +00:00
linked_list.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
logcontext.py Improve the backwards compatibility re-exports of synapse.logging.context (#5617) 2019-07-05 02:32:02 +10:00
logformatter.py Improve the backwards compatibility re-exports of synapse.logging.context (#5617) 2019-07-05 02:32:02 +10:00
macaroons.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
manhole.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
metrics.py Use inline type hints in http/federation/, storage/ and util/ (#10381) 2021-07-15 12:46:54 -04:00
module_loader.py Standardise the module interface (#10062) 2021-06-18 12:15:52 +01:00
msisdn.py Add missing type hints to synapse.util (#9982) 2021-05-24 15:32:01 -04:00
patch_inline_callbacks.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
ratelimitutils.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
retryutils.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
rlimit.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
stringutils.py Simplify exception handling in is_ascii. (#9985) 2021-05-14 10:58:52 +01:00
templates.py Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
threepids.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
versionstring.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00
wheel_timer.py Add types to synapse.util. (#10601) 2021-09-10 17:03:18 +01:00