mirror of
https://github.com/element-hq/synapse.git
synced 2026-03-31 17:05:50 +00:00
Summary of the performance fix: - Synchronous DB for in-memory SQLite: When _use_shared_conn is True (in-memory SQLite with a single shared connection — the test setup), runWithConnection and runInteraction now run the function directly on the event loop thread instead of dispatching to a ThreadPoolExecutor. This eliminates thread context switch overhead for every DB query. - pump() uses asyncio.sleep(0) not asyncio.sleep(0.01): Zero-delay yields drain pending callbacks without burning real wall-clock time. The remaining gap vs Twisted (~14s vs ~6s for login tests) is inherent to IsolatedAsyncioTestCase — each test creates a new event loop, and the _advance_time background task adds per-iteration overhead that Twisted's synchronous pump() didn't have. Further optimization would require either reducing the number of _advance_time iterations or finding a way to process callbacks synchronously like Twisted did.