mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-14 03:08:23 +00:00
`twisted.internet.task.Clock` re-sorts its whole list of pending calls on every `callLater` and after every call it runs. A test homeserver has dozens of pending calls and the threadless database pool schedules a `callLater(0, ...)` per transaction, so this showed up as ~10% of a test's time in profiles. Insert new calls in order with `bisect.insort` and only re-sort after a call was rescheduled with `reset` or `delay`. Together with the previous commit, `tests.rest.client.test_rooms` goes from 44.9s to 32.7s and `tests.handlers` from 146s to 114s single-process on SQLite; a 147-test Postgres subset from 85.9s to 74.4s. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVLsNh6akt4ifEizY4D1ta