Send multipart form bodies in fewer chunks
PA
5h ago+25+25+01234567890123456789-12-12-01234567890123456789
Summary
MultipartStream.iter_chunks() yields four small chunks per field (boundary, headers, value, \r\n). Each chunk turns into its own h11.Data event and its own send() call, so a form with 10 fields and one file makes ~46 writes per request.
This joins everything except file data into one chunk, so the file chunks still pass through without copies. The two render() methods aren't used anymore, so I removed them.
A POST with 10 short fields and a 2 KB file against benchmark/server.py on loopback (sync client, best of 5):
| µs/req | |
|---|---|
| main | 790 - 1170 |
| this PR | 390 - 410 |
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.