Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.

[AutoPerf F050] Avoid numeric quality exceptions in Accept parsing - #51

Draft
jaslawinMs wants to merge 1 commit into
mainfrom
autoperf/F050-accept-header-parse-without-exception
Draft

jaslawinMs wants to merge 1 commit into
mainfrom
autoperf/F050-accept-header-parse-without-exception

Conversation

@jaslawinMs

Copy link
Copy Markdown
Owner

Avoid numeric quality exceptions in Accept parsing

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Avoid numeric quality exceptions in the internal Accept parser

Description

Fork-only AutoPerf F050 measured tradeoff proposal, not a universal net-performance win.

Share the existing media-type parser through an internal double.TryParse quality path using the original number style/culture. Keep the public factory's throwing details by passing its invalid numeric segment back to double.Parse. Preserve original Accept recovery/catch/locals, media-type segment identity/offset/quality and public signatures/defaults. Empty quality at end still keeps its separate ArgumentOutOfRangeException fallback.

Final actual-request formatter selection: three permitted comparisons consumed, with only round3 supporting the final source and corrected checksum harness.39 fixed cases/eight observations per case,234 total outcomes and matching actual producer receipts.

Actual case Final paired time change Before B/op After B/op
Selector_Invalid_1 -73.23% 1920 1464
Selector_Invalid_8 -91.77% 5113 1464
Selector_Invalid_32 -94.73% 16060 1464
Selector_Mixed_8 -83.29% 3289 1464

Explicit tradeoffs: all seven public factory controls are slower. Valid controls are8.73-25.28% slower; public invalid quality is16.23% slower and adds168 B/op (456 to624), despite preserved observed error type/message. Some valid/unsupported parser/selector controls are also slower. Both rejected source shapes and the initial interface-foreach observer are retained; their results are not merged with the single final-source pair. Whether the public-control costs are acceptable needs review.

Immutable complete evidence at8d18a03: all39 final cases, all234 raw measurements/actual receipts, both benchmark projects, exact source/owner hashes, three75-file owner-only closures, all red/green/preparation outcomes, commands and limitations. The final baseline reuses the exact original owning DLL/PDB with byte-identical final harness/deps/runtime/other assemblies.

The inspected dotnet/aspnetcore#70166 optimizes other content-negotiation allocations, not this numeric-quality exception seam. No upstream issue/PR or API shape proposal is created.

Requirement coverage

Requirement Evidence
Actual malformed numeric parsing avoids exceptions while preserving recovery/buffer/offset/default quality AcceptHeaderParserTest.ParseAcceptHeader_InvalidQuality_RecoversWithoutThrowing: all six original rows fail for exactly one actual FormatException; all six final rows pass
Public nonempty quality errors remain FormatException AcceptHeaderParserTest.CreateMediaTypeSegmentWithQuality_InvalidQuality_PreservesPublicException: five rows pass on original/final
Both public empty-quality error partitions remain AcceptHeaderParserTest.CreateMediaTypeSegmentWithQuality_EmptyQualityAtEnd_PreservesPublicException and AcceptHeaderParserTest.CreateMediaTypeSegmentWithQuality_EmptyQualityBeforeComma_PreservesPublicException: pass on original/final

Exact validation commands/results (every session first . .\activate.ps1 from repository root):

dotnet test .\src\Mvc\Mvc.Core\test\Microsoft.AspNetCore.Mvc.Core.Test.csproj -c Release --no-restore -p:UseIisNativeAssets=false -p:BuildNodeJS=false -p:CrossgenOutput=false -p:GenerateInstallers=false -m:2 --verbosity quiet --filter 'FullyQualifiedName~AcceptHeaderParserTest|FullyQualifiedName~MediaTypeTest|FullyQualifiedName~DefaultObjectResultExecutorTest' --logger 'trx;LogFileName=results.trx' --results-directory '<RUN>\tests-after-3'

Passed164/164 targeted tests, all13 unique new reported rows. Both earlier prototypes pass163 each. Original is expected red157/six exact exception-count failures; exact original owner with final test binaries passes158 controls/seven public-contract rows and fails only those same six rows:

dotnet test '<RUN>\tests-original-final-binaries\Microsoft.AspNetCore.Mvc.Core.Test.dll' --filter 'FullyQualifiedName~AcceptHeaderParserTest|FullyQualifiedName~MediaTypeTest|FullyQualifiedName~DefaultObjectResultExecutorTest' --verbosity quiet --logger 'trx;LogFileName=results.trx' --results-directory '<RUN>\tests-before-final'

All five valid suites retain805 passing outcomes/12 expected original failures, no skips. Initial missing-assets/nullable/public-empty expectation/harness-reference preparation evidence is retained separately.

dotnet build '<RUN>\harness-final\AutoPerf.Benchmarks.csproj' -c Release --no-restore -p:UseIisNativeAssets=false -p:BuildNodeJS=false -p:CrossgenOutput=false -p:GenerateInstallers=false -m:2 --verbosity quiet
dotnet '<RUN>\binaries\<snapshot>\AutoPerf.Benchmarks.dll' --verify-setups

Builds passed zero warnings/errors; all five snapshots passed39 original-oracle producer/consumer checks, including measured public exception messages.

dotnet format whitespace .\src\Mvc\Mvc.Core --folder --include .\src\Mvc\Mvc.Core\src\Formatters\MediaType.cs .\src\Mvc\Mvc.Core\src\Formatters\AcceptHeaderParser.cs .\src\Mvc\Mvc.Core\test\Formatters\AcceptHeaderParserTest.cs --verify-no-changes --verbosity quiet
git diff --check

Both passed. All six measured launches passed39 cases/eight observations with this exact command:

dotnet '<RUN>\binaries\<snapshot>\AutoPerf.Benchmarks.dll' --filter '*AcceptHeaderParsingBenchmark*' --inProcess --exporters json csv --artifacts '<RUN>\round-<round>-<variant>' --job Short --warmupCount 3 --iterationCount 8 --iterationTime 100 --outliers DontRemove

Shared Windows host; pinned SDK/runtime, BDN0.13.0, Release/x64/in-process/concurrent server GC; serial builds/tests/measurements with -m:2. No fourth comparison. Whole-MVC functional workflows, HTTP response serialization/network throughput, cold/JIT, contention/memory pressure, other runtimes/platforms and JIT/frame attribution were not verified. Final-source effect-size repeatability is limited to one paired comparison.

Fixes #50

Share the existing media-type parser with an internal non-throwing quality path while preserving public error details. Cover actual comma recovery, exception counts, and public quality errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a24edcfd-1bb9-4160-afce-6ba54b1b7f00

This branch has not been deployed

No deployments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AutoPerf F050] Avoid exception-based Accept quality parsing

1 participant