mirror of https://github.com/zulip/zulip.git
6427d85cf6
This code is called in the hot path when Tornado is processing events. As such, making this code performant is important. Profiling shows that a significant portion of the time is spent calling asdict() to serialize the UserMessageNotificationsData dataclass. In this case `asdict` does several steps which we do not need, such as attempting to recurse into its fields, and deepcopy'ing the values of the fields. In our use case, these add a notable amount of overhead: ```py3 from zerver.tornado.event_queue import UserMessageNotificationsData from dataclasses import asdict from timeit import timeit o = UserMessageNotificationsData(1, False, False, False, False, False, False, False, False, False, False, False) %timeit asdict(o) %timeit {**vars(o)} ``` Replace the `asdict` call with a direct access of the fields. We perform a shallow copy because we do need to modify the resulting fields. |
||
---|---|---|
.. | ||
__init__.py | ||
application.py | ||
descriptors.py | ||
django_api.py | ||
event_queue.py | ||
exceptions.py | ||
handlers.py | ||
ioloop_logging.py | ||
sharding.py | ||
views.py |