From: dvarrazzo (@dvarrazzo) <noreply+dvarrazzo@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: Re: [psycopg/psycopg] PR #1469: perf: don't wait on the event loop when the socket is writable
Date: Sat, 07 Nov 2026 15:18:18 +0000
Message-ID: <gh-psycopg-psycopg-1469-c6708870084@github.com> (raw)
In-Reply-To: <gh-psycopg-psycopg-1469@github.com>
References: <gh-psycopg-psycopg-1469@github.com>
Hello @Alexkane, thank you for the PR!
I've rebased it on master and added a few commits on top of yours:
- `wait_async()` now yields to the loop when 5ms passed since the loop last got control, instead of after 100 skipped waits. A per-call count never yields with many short calls (`copy.write()`, pipeline mode), and a count across calls not with calls far apart (`copy.write_row()`).
- Added `ready_c()` in the C extension, chosen together with `wait_c()` (new `ReadyFunc` protocol in `psycopg.abc`).
Master now has tools to measure this kind of change (#1483, see the README): `tests/scripts/benchmark.py` (the former `waittest.py`, with your workloads) and `bench_compare.py`. The full comparison against master is in [this run](https://github.com/dvarrazzo/psycopg/actions/runs/42335242456); the summary, on GitHub runners (median):
| | Linux | macOS | Windows |
|---|--:|--:|--:|
| async pipeline | -64% | -67% | -62% |
| async executemany | -65% | -72% | -62% |
| loop max stall, COPY | 207 -> 5 ms | 4 -> 5 ms | 194 -> 5 ms |
No regressions found, sync unchanged.
I'm going to merge it now, as other work depends on it: sorry for the hurry. If you see anything to improve, or want to work on other performance improvements, follow-up PRs are very welcome!