Skip to content

Use global enum members for parser state lookups - #330

Merged
Kludex merged 1 commit into
mainfrom
use-global-parser-states
Sep 25, 2026
Merged

Kludex merged 1 commit into
mainfrom
use-global-parser-states

Conversation

@Kludex

@Kludex Kludex commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Use enum.global_enum to export parser state members and access them directly in the parsing loops. Bindings inside TYPE_CHECKING make 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> to multipart.END.

Performance

Local CPython 3.12.3 on macOS ARM64, 60 interleaved timeit batches with a fresh parser per iteration and a 10% trimmed mean:

Workload Before After Throughput gain
Multipart, two fields 10.52 µs 8.95 µs 17.5%
Multipart, 100 fields 427.30 µs 356.93 µs 19.7%
Querystring, 100 fields 58.81 µs 53.10 µs 10.8%
Multipart, one-byte chunks 277.10 µs 262.13 µs 5.7%
Multipart, 8 MiB upload 630.51 µs 616.01 µs 2.4%
Defnull blocking adapter, 100 fields 643.34 µs 573.60 µs 12.2%

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 main in 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.

Review in cubic

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T07:22:39.121392Z 23773fa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codspeed

codspeed Bot commented Sep 25, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 13.49%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 3 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread python_multipart/multipart.py
@Kludex
Kludex merged commit 212819d into main Sep 25, 2026
14 checks passed
@Kludex
Kludex deleted the use-global-parser-states branch September 25, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant