Spaces:
Running
Running
Commit History
-
perf(http): share one pooled client instead of handshaking per call
siddhm11 +1: Claude Opus 5Six call sites built their own httpx.AsyncClient inside an `async with`, which closes the connection pool at the end of the block. So every Turso metadata fetch, arXiv fallback, 60s replication tick and deep health check paid a full DNS + TCP + TLS handshake to a destination that never changes. Measured against live Turso, five calls each: per-call client 413 134 143 150 141 median 143ms pooled client 145 39 29 30 31 median 31ms -> 112ms saved on every request after the first The client rebinds when the running event loop changes. An AsyncClient holds loop-bound connections that do NOT report themselves closed — they raise "Event loop is closed" on next use. pytest builds a fresh loop per test, so caching across loops broke a previously-passing arXiv test immediately. Two tests pin it. Also lands the response-header middleware, since it shares main.py: gzip (117KB of CSS+JS -> 35KB, 70%), Cache-Control on /static, nosniff, strict-origin-when-cross-origin (every ca…54b1a49