Trim avoidable work from async requests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 78
- Avg merge
- 8h 59m
- Merged PRs (30d)
- 24
Description
This came out of profiling the asyncio request path in discussion #1181.
There are three small costs we can skip:
- Building a cancellation shield when the pool has no connections to close.
- Copying client headers when a request does not add any.
- Running unencoded response chunks through no-op chunking work.
The combined local result is about 4-6% more throughput and 4-6% less client CPU per request:
| Scenario | Requests/s | Client CPU/request |
|---|---|---|
| c1 / 1 KiB | 4,710 -> 4,994 (+6.0%) | 210.0 -> 198.1 us (-5.7%) |
| c32 / 1 KiB | 4,568 -> 4,813 (+5.4%) | 217.2 -> 206.2 us (-5.1%) |
| c32 / 64 KiB | 3,941 -> 4,114 (+4.4%) | 251.7 -> 241.1 us (-4.2%) |
The benchmark used plain HTTP/1.1 on loopback, CPython 3.14.7, stdlib asyncio, pinned CPUs, and five interleaved 2.5-second runs.
- Initially raised as discussion #1181
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading discussion #1181 and profiling the asyncio request path described there. Locate the pool-close, client-header, and response-chunk handling involved in the three listed costs. Done means each avoidable operation is skipped in its stated case without changing request behavior, and the reported benchmark improvements can be reproduced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100