mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-15 13:30:47 +00:00
Rust code increasingly needs the current time somewhere it cannot cheaply ask Python for it: on a Tokio worker without the GIL, or deep inside a data structure where reaching back out to a `synapse.util.clock.Clock` would mean threading a `Py<PyAny>` through everything. Up to now there was no clock at all in `rust/src` — the rendezvous handlers each held a `Py<PyAny>` and called `time_msec()` on it per request. Add `synapse::clock`, a wall clock matching `Clock.time_msec()` so times mean the same thing on both sides of the boundary. It reads `SystemTime::now()`, which on Linux is a vDSO call rather than a syscall. Synapse's tests run against a virtual reactor clock, and it is important that time in tests only moves when a test says so. The test reactor therefore pins this clock to its own time; `tests.unittest.TestCase` unpins it afterwards so it cannot leak between tests. Port both rendezvous handlers over, which removes a Python round-trip per rendezvous request and exercises the virtualisation against the existing tests that drive session eviction by advancing the reactor. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyuiV3m44ZbK9o24EnMMES