Speed up opening boundary matching

Merged
KL
2mo ago
+21-0

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 formBeforeAfterLess parsing time
MultipartParser22.01 µs14.39 µs34.6%
FormParser, collecting fields30.63 µs22.72 µs25.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 on main.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.