Use generated regexes for gRPC JSON parsing#67758
Draft
artl93 wants to merge 4 commits into
Draft
Conversation
added 2 commits
July 12, 2026 14:06
Replace the runtime-compiled timestamp and duration regexes with source-generated equivalents, add semantic differential coverage, and benchmark parser and JSON deserialization paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61f16215-869e-496a-bb38-7175bebdd2db
Benchmark timestamp writing and field-mask validation alongside timestamp and duration parsing so generated-regex measurements include unaffected control paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61f16215-869e-496a-bb38-7175bebdd2db
added 2 commits
July 19, 2026 10:55
Refresh the draft PR on the current ASP.NET Core baseline before readiness validation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61f16215-869e-496a-bb38-7175bebdd2db
Update the draft PR to the current ASP.NET Core baseline for readiness validation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61f16215-869e-496a-bb38-7175bebdd2db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
gRPC JSON transcoding currently creates two process-wide
RegexOptions.Compiledregexes for protobuf timestamp and duration parsing. Their first use performs runtime regex parsing/code-generation work and allocates about 52-58 KiB on the measured thread. This is avoidable for static patterns and is most relevant to cold/serverless/scale-to-zero processes and first-request latency.Change
[GeneratedRegex]accessors while preserving the exact patterns andRegexOptions.Compiledvalue.There is no public API change. The accessors are
internalonly so the friend test assembly can compare the generated regexes directly.BenchmarkDotNet and process-start evidence
Exact current comparison:
d516a8d1efd70e1f6b0dd023407b100622adc16e1aed9b4ab810cf1d1a329e730fc89001c11d2705eed49381a6f7d65558d63acbb4b940e67c42bfdf2b659f8ed8a7c4d0e075cedfWarm BDN
The controls move in opposite directions and by more than most parser deltas, so the correct conclusion is warm throughput and allocation are neutral within run-to-run noise. This PR does not claim a steady-state throughput win.
Cold first use
100 interleaved fresh processes per implementation/path. Complete-process time is measured outside the child; the inner first invocation is timed directly around the unchanged reflected method call.
The robust result is removal of 51-57 KiB of one-time current-thread allocation and a 2-4 ms reduction in this focused fresh-process harness. Real application startup includes descriptor registration, DI, hosting, and Kestrel, so the end-to-end impact in a full app will be smaller.
The product DLL grows from 142,848 to 147,456 bytes (+4,608 bytes on disk).
Raw current evidence:
be503aacf41dc0d9836e87d54baf35285b508ba8dedf6947dc44ff6e4ae009e8c345db63fd140b7a95d83e8cf8b8e352eb63474f1b6b4711acbfceb01ff99b8dd28c535449cc4552028ace182c26cea44298dc7b4b760f13eef80206a5f7132f32f83145cf432f35308872759a60128dc54cee23a13eb2670e5cd79d36501fa217ae8713a64a98abc30db42839a606b3f69e5a0bf6d6d1fa095db8553eea15EgorBot v2 is documented as a
dotnet/runtimeservice and does not builddotnet/aspnetcore; it also does not support NativeAOT. A Linux Arm64 Docker BDN campaign with identical detached parent/final worktrees is prepared as the cross-platform substitute, but remains pending because the local Docker daemon is unavailable.Validation
NuGetAudit=false ./src/Grpc/build.sh -test: succeeded, 0 warnings, 0 errors.Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests: 340 passed.Microsoft.AspNetCore.Grpc.JsonTranscoding.IntegrationTests: 24 passed.Legacy.csis compiled into JsonTranscoding and Swagger).Current PR CI is blocked by a repository-wide
NU1902for AngleSharp 0.9.9 / GHSA-pgww-w46g-26qg in unrelated MVC, Identity, and Security projects. The exact-base main build and unrelated PRs fail identically; platform builds still restore/build/package this gRPC product successfully. This PR intentionally does not modify or suppress that unrelated dependency issue.Risks and limits
$behavior, fractions, offset boundaries, negative/invalid durations, cultures, Unicode digits, exact exceptions/messages, and 100,000-character malformed inputs.AI disclosure
The implementation, tests, benchmark harness, measurements, and PR analysis were AI-assisted. Two independent code reviews and two skeptical performance/AOT reviews found no correctness issue and required the conservative warm-neutral/AOT-scoped framing above. Human owner review is still required before this draft is marked ready.