Skip to content

Add CodSpeed benchmark suite for parser hot paths#276

Merged
Kludex merged 5 commits into
mainfrom
add-codspeed-benchmarks
May 10, 2026
Merged

Add CodSpeed benchmark suite for parser hot paths#276
Kludex merged 5 commits into
mainfrom
add-codspeed-benchmarks

Conversation

@Kludex

@Kludex Kludex commented May 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • add tests/benchmarks/ covering MultipartParser, FormParser, parse_form, OctetStreamParser, and QuerystringParser
  • add pytest-codspeed to the dev dependency group
  • add .github/workflows/benchmark.yml running CodSpeed in instrumentation mode on push to main and on pull requests

Why

Without continuous benchmarking we have no signal on parser performance regressions across PRs. This wires up CodSpeed to track parsing latency on the hot paths we actually care about.

The structure mirrors uvicorn's CodSpeed setup: a benchmarks directory under tests/, a top-level pytest.mark.benchmark marker on each module, and a workflow that runs pytest tests/benchmarks/ --codspeed via CodSpeedHQ/action.

Coverage of scenarios:

  • MultipartParser: single-chunk parse, fragmented (64 B chunks), 2 MiB file streamed in 16 KiB chunks, parametrized partial-boundary scan across boundary lengths (16, 64, 256, 1024 B), many small parts.
  • FormParser: multipart and urlencoded paths.
  • parse_form: parametrized across body sizes (1 KiB, 64 KiB, 1 MiB).
  • OctetStreamParser and QuerystringParser: streamed and fragmented.

The benchmarks also pass as plain pytest tests (no --codspeed), so they run alongside the regular suite. Coverage stays at 100% (tests/* is already excluded).

Test plan

  • pytest tests/benchmarks/ passes locally (16 tests)
  • pytest tests/benchmarks/ --codspeed runs cleanly in walltime mode locally
  • full scripts/test still hits 100% coverage (157 tests total)
  • CodSpeed instrumentation run on this PR

AI Disclaimer

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

Comment thread .github/workflows/benchmark.yml Fixed
@codspeed-hq

codspeed-hq Bot commented May 10, 2026

Copy link
Copy Markdown

Congrats! CodSpeed is installed 🎉

🆕 5 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7241a651f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/benchmarks/test_basic_parsers.py Outdated
Five benchmarks in tests/test_benchmarks.py covering the parsers
Starlette actually uses (MultipartParser and QuerystringParser):

- multipart small form (typical login-style fields)
- multipart file upload (2 MiB file in 64 KiB chunks)
- multipart mixed form (fields plus file in chunked stream)
- urlencoded small form
- urlencoded large form fragmented

Adds pytest-codspeed as a dev dep and a CodSpeed workflow that runs
in instrumentation mode on push to main and on pull requests.
@Kludex Kludex force-pushed the add-codspeed-benchmarks branch from b7241a6 to f1e3395 Compare May 10, 2026 09:04
Kludex added 4 commits May 10, 2026 11:09
mypy --strict rejected the bare dict literal because the noop callable
did not unify with the typed callback signatures. Splitting noop into
event-shaped and data-shaped helpers and annotating the dicts with the
exported TypedDicts satisfies the checker.
Inspired by defnull/multipart_bench: long random-shaped boundary
matching what browsers emit, varied payload bytes via
string.printable, and a worstcase scenario where the body contains
partial-boundary character matches to exercise the find-miss tail
scan. Five scenarios: simple form, 100-field form, 8 MiB file
upload, worstcase boundary chars, and a 100-field urlencoded form.
@Kludex Kludex merged commit 03df045 into main May 10, 2026
14 checks passed
@Kludex Kludex deleted the add-codspeed-benchmarks branch May 10, 2026 09:15
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.

2 participants