Add asyncio network backend
MI
2d ago+829+829+012345678901234567890123456789-0-0-0123456789
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):
| Idle | anyio | asyncio | Change |
|---|---|---|---|
| 1 | 386 µs | 351 µs | -9% |
| 10 | 411 µs | 366 µs | -11% |
| 100 | 579 µs | 508 µs | -12% |
| 500 | 1339 µs | 1284 µs | -4% |
benchmark/run.py --quick (Python 3.14, median of 3 rounds, with a local tweak to pick the backend):
| Scenario | httpcore2 rps | httpx2 rps |
|---|---|---|
| c16/1k | 1,999 → 2,505 (+25%) | 1,813 → 1,936 (+7%) |
| c512/1k | 872 → 933 (+7%) | 819 → 783 (-4%) |
| c64/100k | 1,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.