Use global enum members for parser state lookups - #330
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will improve performance by 13.49%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_parse_multipart_large_form |
8.3 ms | 7.2 ms | +16.25% |
| ⚡ | test_parse_querystring_large_form |
1.3 ms | 1.1 ms | +10.8% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing use-global-parser-states (23773fa) with main (1aaac89)
Footnotes
-
5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Use
enum.global_enumto export parser state members and access them directly in the parsing loops. Bindings insideTYPE_CHECKINGmake the exports visible to mypy and Ruff without runtime alias assignments.The enum classes, values, and member identities are retained. As expected with
global_enum, member representations change from forms like<MultipartState.END: 12>tomultipart.END.Performance
Local CPython 3.12.3 on macOS ARM64, 60 interleaved
timeitbatches with a fresh parser per iteration and a 10% trimmed mean:Validation
162 tests pass on Python 3.11 with 100% package coverage, including one test that parser states remain the original enum members. Ruff, mypy, source-distribution, and import-compatibility checks pass; 176,524 multipart and 100,000 querystring differential cases match
mainin their callbacks, consumed lengths, and errors.AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.