Speed up opening boundary matching
Merged
KL
2mo ago+21+21+01234567890123456789-0-0-0123456789
Match complete opening boundaries with bytes.startswith(), retaining byte-by-byte parsing for fragmented or mismatched boundaries and the existing delimiter validation. Keep one regression test for max_size truncating the opening boundary; existing tests cover chunk splitting and malformed boundaries.
Performance
Local CPython 3.13.4 on macOS ARM64, medians of 15 interleaved timeit runs with a fresh parser per iteration:
| Two-field form | Before | After | Less parsing time |
|---|---|---|---|
MultipartParser | 22.01 µs | 14.39 µs | 34.6% |
FormParser, collecting fields | 30.63 µs | 22.72 µs | 25.8% |
Large uploads and one-byte chunks were effectively unchanged; these are parser timings, not HTTP throughput measurements.
Validation
- 161 tests pass with 100% package coverage.
- Ruff, mypy,
check-sdist, and the lockfile check pass. - The new regression test passes with
-W error; the full suite exposes three existing unclosed-file warning failures, reproduced onmain.
AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.