Add asyncio network backend

MI
2d ago
+829-0

Summary

Adds httpcore2.AsyncIOBackend, a network backend built directly on asyncio streams, without anyio. It's opt-in for now: AutoBackend still uses AnyIOBackend.

It also does its own happy eyeballs (RFC 8305), so it behaves the same on uvloop, which doesn't support happy_eyeballs_delay.

The stale connection check first looks at what asyncio has already read (EOF, error or buffered data), and only polls the socket if there's nothing there.

Idle connections (time per request, median of 3 rounds, rebased on #1352):

IdleanyioasyncioChange
1386 µs351 µs-9%
10411 µs366 µs-11%
100579 µs508 µs-12%
5001339 µs1284 µs-4%

benchmark/run.py --quick (Python 3.14, median of 3 rounds, with a local tweak to pick the backend):

Scenariohttpcore2 rpshttpx2 rps
c16/1k1,999 → 2,505 (+25%)1,813 → 1,936 (+7%)
c512/1k872 → 933 (+7%)819 → 783 (-4%)
c64/100k1,358 → 1,701 (+25%)1,219 → 1,450 (+19%)

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.