Create a fresh parser per benchmark iteration - #318
Conversation
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
The latest CodSpeed run now reports five new complete-parse benchmarks and no performance regression, so the corrected baseline is established successfully. The five old benchmarks are skipped because their ended-parser measurements were intentionally replaced. No further code change is needed. |
|
The failing CodSpeed comparison was between two different workloads, not a package regression. In c3186eb I renamed the benchmark functions to start a new CodSpeed series for complete request parses. This prevents comparison against the old ended-parser measurements and gives follow-up performance PRs a valid baseline. |
Summary
Why
CodSpeed invokes each benchmark function repeatedly while retaining its pytest fixtures. The multipart fixture previously yielded one parser for the entire benchmark run. After the first invocation that parser was in
MultipartState.END, so later iterations only discarded input.The querystring fixture had a similar lifecycle problem: repeated invocations continued from the previous parser state, and
finalize()ran only once after all measured iterations.The broken lifecycle was visible locally because the simple and 100-field multipart benchmarks had nearly identical simulated costs. With a fresh parser per invocation, the 100-field benchmark performs far fewer iterations and correctly measures the complete parse.
CodSpeed report
CodSpeed now reports five new benchmarks and no performance regression, establishing the corrected baseline successfully. The five old benchmark identifiers are skipped because their ended-parser measurements are intentionally replaced.
This PR deliberately changes the measured workload. The base branch parses the multipart input only on the first benchmark iteration; subsequent iterations write to a parser already in
MultipartState.ENDand discard the input. The head branch parses the complete request on every iteration.The benchmark functions are renamed from
test_multipart_*totest_parse_multipart_*(and likewise for querystrings) because these are new benchmark semantics, not comparable performance measurements. This establishes a clean CodSpeed baseline for complete request parses and prevents the ended-parser measurements from being reported as package regressions.Validation