Repository navigation
Agent suggestions
Public previewDescription
ASP.NET Core perf effort: summary of open performance PRs
Status: nothing is merged yet. Everything below is an open PR awaiting maintainer review. The numbers are expected improvements from those PRs, not shipped gains.
Approach
- AI agent sessions ("workers") are each assigned one area of ASP.NET Core. They check existing PRs first to avoid duplicating work.
- Workers read the hot paths to find avoidable allocation and CPU work. They measure each candidate with BenchmarkDotNet A/B runs (main vs. PR, 3 interleaved rounds with MemoryDiagnoser).
- A candidate becomes a PR only if its benchmark shows a measurable win. Candidates whose gains are too small to matter are dropped.
- Each win gets one focused PR, with no public API or behavior changes and no unsafe code (see Rules below).
- A periodic automated, read-only check ("triage") runs about every 20 minutes and covers CI, review threads and conflicts for every open perf PR. A worker is started to fix or answer each PR it flags. Real CI failures are fixed. Flaky failures are retriggered with an empty commit plus a comment explaining the evidence.
- Nothing is merged without maintainer review and approval.
- All agents (coordinator and workers) ran on Claude Opus 5.5 (claude-opus-5.5) via GitHub Copilot.
Human involvement: it wasn't magic or hands-off
My involvement wasn't just supplying a prompt. I was setting constraints, asking for measurements, and providing engineering judgment throughout the run. Here are some actual messages, with spelling preserved.
Defining the work and requiring evidence
Look for more opportunities to improve the performance of the whole stack. Go component by component and do it, measure, test, experiment and then make a PR if it's good. Use minimum of 5 concurrent sessions to do this work
Keeping compatibility in scope
Consider breaking changes. We don’t want to change public APIs to breaking changes. We can consider new APIs but that’s a hassle as well. Stick to internal implementation that we can optimize.
Flagging the risks behind an optimization
Changing object lifetimes, pooling are possible but consider data exposed to callers or customers
Reinforcing correctness
Consider also that we need to make sure PRs are green, it has to work not just be fast
Applying engineering judgment
We're trying to avoid as much unsafe code as possible. Better to build on really efficient BCL primitives instead of custom vectorization in most cases. Only extremely isoalted casses warrant it
Rules
Every change and every worker follows these rules:
- No public API, breaking or behavior changes.
- Pool or cache only when nothing pooled or cached is reachable by callers or leaks between requests.
- No unsafe code. Prefer BCL primitives such as
SearchValues,IndexOfAnyandAscii. - Each change ships with A/B benchmarks (3 interleaved rounds with MemoryDiagnoser) and passing tests.
- Comments and PR descriptions posted by workers end with an AI-agent signature.
Executive summary
An AI-agent-driven effort to cut allocation and CPU overhead on ASP.NET Core hot paths, one component at a time.
- 93 open PRs across 10 areas. Each is small and focused, comes with its own BenchmarkDotNet A/B results, and is designed to make no public API, breaking or behavior changes.
- About the numbers: headline figures are BenchmarkDotNet microbenchmarks of the specific code path changed (main vs. PR, interleaved A/B runs with MemoryDiagnoser). They are not end-to-end application throughput.
- CI: green on all open PRs except:
- 5 PRs whose only failing leg is
aspnetcore-components-e2e, which also fails on main.Build AnalysisandBuild Insightsare red on those PRs only because of that leg. - Avoid sorting small PrefixContainer key sets in value providers #70209, whose CI is still running.
- 5 PRs whose only failing leg is
- Reviews: all review threads have been answered, either with a fix and a commit link or with evidence. Some are left open for a maintainer to decide.
- Merging: a PR is merged only after a maintainer approves it and CI is green. None are approved yet.
- Next: 4 parallel workers are looking for wins in the Identity stack. They have opened 10 Identity and auth PRs so far (Avoid allocating a token substring when authenticating bearer tokens #70218 and Cache the absence of authorization metadata in AuthorizationMiddleware #70220–Use span-based data protection in SecureDataFormat #70228), listed under Identity and Security / auth in the full PR list.
Areas and changes
| Area | PRs | What changed |
|---|---|---|
| Kestrel / HTTP/2 / HTTP/3 | 8 | No string allocation for Content-Length, HPACK hashing, header append and validation fast paths, lazy HTTP/3 buffers |
| HTTP abstractions / headers / forms | 14 | Content-type fast paths, single-pass query and cookie decoding, multipart reads without MemoryStream, header formatting |
| Routing | 6 | DFA (deterministic finite automaton) matcher candidate sharing and pruning, policy edge building, link generation |
| Middleware | 16 | Response compression, output and response caching, CORS, static files and assets, logging, forwarded headers, rate limiting |
| Security / DataProtection / auth | 14 | Managed encryptor and AES-GCM in-place writes, TicketSerializer, authorization handler enumeration, bearer token authentication, ticket protection |
| MVC / Razor Pages | 11 | Model binding and validation, view rendering and lookup, content negotiation, tag helpers |
| Identity | 7 | PasswordValidator, UserValidator, UserManager construction, TOTP (time-based one-time password) and Base32, metrics and logger caching |
| Blazor / Components | 7 | RenderBatchWriter, keyed diff, SSR (server-side rendering) text writer, JS interop buffers |
| SignalR | 8 | Protocol parsing, hub activation, client target lookup, groups, streaming |
| OpenAPI | 2 | Resolving references, caching attribute lookups |
Details: full PR list, status, incidents
Full PR list (93 open, 4 closed)
Kestrel / HTTP/2 / HTTP/3
- Avoid allocating the Content-Length string when writing HTTP/2 and HTTP/3 response headers #70117: Content-Length header without allocating a string
- Reuse Http3RawFrame across pooled HTTP/3 streams #70118: reuse Http3RawFrame
- Use ulong.TryFormat for Content-Length values >= 1000 in Kestrel #70136:
ulong.TryFormatfor Content-Length - Reduce HPACK dynamic table name hashing #70157: HPACK name hashing
- Kestrel: avoid name allocation and extra lookups when appending unknown request headers #70158: unknown request header append
- Kestrel: vectorize query string end search in HTTP/1.1 request line parsing #70162: query string end search
- Fast path for HTTP/2 and HTTP/3 :path validation #70184: :path validation fast path
- Allocate the HTTP/3 header encoding buffer on first use #70189: lazily allocate the HTTP/3 header buffer
HTTP abstractions / headers / forms
- Add allocation-free fast path to HasJsonContentType #70119: HasJsonContentType fast path
- Avoid intermediate allocation when decoding query string names/values #70120: single-pass query decode
- Vectorize skipping of empty values in header list parsing #70121: skipping empty header values
- Avoid LINQ and intermediate strings in SetCommaSeparatedValues #70134: SetCommaSeparatedValues
- Avoid per-line MemoryStream in BufferedReadStream.ReadLine #70156: multipart ReadLine without a MemoryStream
- Avoid allocating HttpContext.Items in hosting RequestEnd #70161: hosting RequestEnd Items
- Avoid parsing Content-Type and allocating Items in HasFormContentType #70163: HasFormContentType fast path
- Avoid StreamReader allocations in MultipartSection.ReadAsStringAsync #70164: multipart ReadAsStringAsync
- Avoid Split/ToArray allocations in ContentDispositionHeaderValue MIME decoding #70182: ContentDisposition MIME decoding
- Avoid intermediate substring when unescaping request cookie values #70186: cookie unescape
- Reduce allocations in QueryHelpers.AddQueryString #70200: AddQueryString
- Avoid parsing common Content-Type values when resolving response encoding #70201: content result encoding
- Reuse a cached StringBuilder when formatting header values #70203: header value formatting
- Avoid StringBuilder when encoding Content-Disposition file names #70204: Content-Disposition RFC 5987 encoding
Routing
- Reduce allocations in DefaultLinkGenerator #70127: DefaultLinkGenerator
- Share per-endpoint candidate data when building the DFA matcher #70138: DFA matcher builder candidate sharing
- Skip processing lower-priority candidates once a match is found in DfaMatcher #70152: DfaMatcher skips lower-priority candidates
- Reduce allocations in HttpMethodMatcherPolicy.GetEdges #70154: HttpMethodMatcherPolicy.GetEdges
- Reuse work lists in DfaMatcherBuilder.ApplyPolicies #70159: ApplyPolicies work lists
- Vectorize FastPathTokenizer #70160: FastPathTokenizer (draft)
Middleware
- Avoid HashSet and LINQ when selecting a response compression provider #70132, Avoid per-response allocations when matching Content-Type in ResponseCompressionProvider #70197: response compression
- Reduce allocations in CorsService.EvaluatePolicy #70145: CORS
- Reduce allocations in output/response caching key generation and policy collection #70148, Use exact-size header arrays for output cache entries #70195, Avoid per-request policy list, enumerator and tag set allocations in OutputCacheMiddleware #70199: output and response caching
- Reduce allocations in RequestLocalizationMiddleware #70155: localization
- Reduce allocations when serializing DistributedSession #70169: session
- Reduce per-request work in StaticAssetsInvoker #70170: static assets
- Reduce per-request allocations in StaticFileMiddleware #70173: static files
- Reduce per-request allocations in W3CLoggingMiddleware #70176: W3C logging
- Avoid per-request allocations in ForwardedHeadersMiddleware #70177: forwarded headers
- Reduce per-request allocations and CPU in RewriteMiddleware #70178: rewrite
- Skip the endpoint rate limiter when the endpoint has no rate limiting policy #70180: rate limiting
- Pre-size the HttpLogging parameter lists #70181: HttpLogging
- Avoid allocating HttpContext.Items in StatusCodePagesMiddleware when unused #70179: StatusCodePages (on hold pending a decision)
Security / auth / DataProtection
- Reduce allocations in managed DataProtection protect/unprotect #70146: managed encryptor protect and unprotect
- Reduce allocations in DataProtection string Protect/Unprotect #70187: string Protect/Unprotect overloads
- Avoid intermediate copies in TimeLimitedDataProtector #70191: TimeLimitedDataProtector
- Build the DataProtection AAD template lazily #70192: lazy AAD (additional authenticated data) template
- Write AES-GCM key modifier and nonce directly into the output buffer #70193: AES-GCM nonce and key modifier written in place
- Read authentication tickets directly from the payload buffer #70165, Reduce allocations when serializing authentication tickets #70172: TicketSerializer read and write
- Avoid enumerator allocations when evaluating authorization handlers #70147: authorization handler enumeration
- Materialize trimmed [Authorize] roles once in AuthorizationPolicy.CombineAsync #70183: [Authorize] roles combine
- Avoid allocating a token substring when authenticating bearer tokens #70218: avoid allocating a token substring when authenticating bearer tokens (−16% allocation per request)
- Cache the absence of authorization metadata in AuthorizationMiddleware #70220: AuthorizationMiddleware caches endpoints without authorization metadata (~164 ns/40 B → ~87 ns/0 B per request, about 47% less time)
- Avoid ClaimsPrincipal.Claims iterator allocations in ClaimsAuthorizationRequirement #70221: ClaimsAuthorizationRequirement without Claims iterator allocations (about 35–40% faster, 768 B → 632 B per check)
- Avoid an extra task allocation in DefaultAuthorizationServiceImpl.AuthorizeAsync #70225: authorization service returns the completed task without an extra allocation (632 B → 560 B per check, 72 B less; ~5–10% faster in most rounds)
- Use span-based data protection in SecureDataFormat #70228: SecureDataFormat uses ISpanDataProtector (ticket Unprotect allocations −14–15%, Protect −24–26%, cookie AuthenticateAsync −7%)
MVC / Razor Pages
- Skip ValidationContext allocation for valid values of built-in DataAnnotations attributes #70126: DataAnnotations fast path
- Reduce per-render allocations in RazorPage, RazorView and RazorViewEngine #70128: RazorPage/RazorView render
- Reduce allocations in MVC model validation #70129, Avoid per-parameter validation allocations for simple models #70210: model validation
- Lazily allocate TemplateInfo visited objects set #70130: TemplateInfo
- Lazily allocate and right-size the model binding state stack #70131: model binding stack
- Reduce allocations in output formatter content negotiation #70166: content negotiation
- Reduce allocations in InputTagHelper rendering #70167: InputTagHelper
- Avoid sorting small PrefixContainer key sets in value providers #70209: PrefixContainer small sets
- Avoid ViewLocationExpanderContext allocations on Razor view lookup cache hits #70211: view lookup expander context
- Select Razor Pages handlers without allocating a candidate list #70212: page handler selection
Identity
- Cache Identity UserManager/SignInManager metrics per IMeterFactory #70174: Identity metrics cache
- Cache SecurityStampValidator logger per ILoggerFactory #70175: SecurityStampValidator logger cache
- Reduce UserManager construction cost #70222: UserManager construction (about 104 B less per construction, 4.23 KB → 4.13 KB per resolve)
- Avoid LINQ and allocations in PasswordValidator #70223: PasswordValidator without LINQ (~240 ns/832 B → ~17 ns/72 B per valid password)
- Reduce per-call overhead in UserValidator #70224: UserValidator with cached SearchValues and a shared EmailAddressAttribute (~143 ns/320 B → ~84 ns/296 B, about −42%)
- Speed up TOTP validation by reusing the HMAC and input buffer across timesteps #70226: TOTP validation reuses one HMAC and input buffer across timesteps. About 21% faster on a match and 35% faster on a miss; 520 B → 352 B per failed validation for modifier-based providers. Trade-off: the authenticator-app path (no modifier) goes from 0 B to about 296 B per validation, in exchange for about 2 µs less CPU.
- Speed up Base32.FromBase32 decoding for authenticator keys #70227: Base32.FromBase32 with range checks and a 5-bit accumulator (~230 ns → ~49 ns per authenticator key, about 4.6× faster)
Blazor / Components
- Write RenderBatchWriter frames and edits as single fixed-size records #70125: RenderBatchWriter
- Avoid redundant dictionary lookups when diffing keyed items #70133: keyed diff
- Reset BufferedTextWriter char segment buffer between flushes #70139, Coalesce small writes in BufferedTextWriter (static SSR) #70150: SSR BufferedTextWriter
- Use pooled buffer for UTF-8 payload in DotNetDispatcher.EndInvokeJS #70140: EndInvokeJS pooled buffer
- Classify element names once in StaticHtmlRenderer #70151: StaticHtmlRenderer element kind
- Allocate a component's second RenderTreeBuilder on demand #70153: lazy second RenderTreeBuilder
SignalR
- Avoid per-header allocations in SignalR hub protocols #70137: protocol headers
- Avoid resolving the default IHubActivator from DI on every hub invocation #70141: hub activator
- Avoid allocating the target string per invocation received by the .NET SignalR client #70142: client target lookup
- Reduce allocations when parsing SignalR MessagePack messages #70143: MessagePack parsing
- Skip streaming-type reflection for primitive SignalR client arguments #70149: client stream argument check
- Avoid closure allocations and lock-all Count when adding a SignalR connection to a group #70185: group add
- Cache SignalR stream converter factories instead of reflecting per uploaded stream #70188: stream converter cache
- Avoid parsing the Accept header on non-SSE SignalR connection GETs #70190: SSE Accept prefilter
OpenAPI
- Avoid rebuilding and redundantly cloning OpenAPI schema trees when resolving references #70168: resolving references
- Avoid materializing all custom attributes during OpenAPI schema generation #70171: attribute lookups
Closed as duplicates:
- Avoid resolving the default hub activator from DI for every hub invocation #70144 (duplicate of Avoid resolving the default IHubActivator from DI on every hub invocation #70141)
- Avoid per-line MemoryStream allocation in BufferedReadStream.ReadLine #70194 (Avoid per-line MemoryStream in BufferedReadStream.ReadLine #70156)
- Skip MediaTypeHeaderValue parsing for common JSON request content types #70196 (Add allocation-free fast path to HasJsonContentType #70119)
- Avoid a StreamReader per multipart form value in ReadAsStringAsync #70198 (Avoid StreamReader allocations in MultipartSection.ReadAsStringAsync #70164)
Status
- Skip processing lower-priority candidates once a match is found in DfaMatcher #70152, Avoid per-line MemoryStream in BufferedReadStream.ReadLine #70156, Avoid parsing Content-Type and allocating Items in HasFormContentType #70163, Avoid Split/ToArray allocations in ContentDispositionHeaderValue MIME decoding #70182 and Reuse a cached StringBuilder when formatting header values #70203 fail only
aspnetcore-components-e2e, which also fails on main.Build AnalysisandBuild Insightsare red on these PRs only because of that leg. Each PR has an evidence comment. - Reduce allocations in managed DataProtection protect/unprotect #70146 and Avoid allocating a token substring when authenticating bearer tokens #70218 are green.
- Avoid sorting small PrefixContainer key sets in value providers #70209 has CI running.
- Vectorize FastPathTokenizer #70160 is a draft. Avoid allocating HttpContext.Items in StatusCodePagesMiddleware when unused #70179 is on hold pending a design decision.
Incidents and lessons
- A CI retrigger once pushed a commit with an empty tree. It was rolled back, and retriggers now verify the diff before and after pushing.
- A full-repo restore filled the disk. Workers now build only the projects they need.
- Long blocking waits stalled workers. Builds and benchmarks now run in the background with capped retries.
- Recurring flaky tests:
CanResolveServices, Blazor Virtualization,NavigationLockandVariableHeight_HtmlTableE2E, and KestrelHttp2 StreamPool. - The first Reduce allocations in managed DataProtection protect/unprotect #70146 benchmark measured CNG instead of the managed path on Windows. It now pins the managed encryptor configuration.
In progress: Identity stack
Four parallel workers are covering the areas below. The 10 Identity and auth PRs (#70218 and #70220–#70228) came from this work.
- SignInManager, UserManager, the claims principal factory and SecurityStampValidator.
- Extensions.Core: password hasher, TOTP, token providers and passkeys.
- Cookie auth, ticket serialization, authorization and the EF Core stores.
- MapIdentityApi, bearer tokens and Identity UI.
🤖 Posted by ASP.NET Core Perf 2 (AI Agent)
Activity
github-actions commentedon Nov 1, 2026
Triage Summary
Area:
area-perf(cross-cutting summary of performance PRs spanning many areas)Type:
Task(tracking/summary issue; no broken behavior or new feature requested)Potential Duplicates
davidfowl commentedon Nov 2, 2026
Perf effort status: the good, the bad and the ugly (2026-11-19, 23:40 UTC)
TL;DR
perf/*PRs in this effort now stand at 40 merged, 34 open, 25 closed unmerged (since the 2026-11-19 08:51 UTC report: 0 / 0 / 0). This counts davidfowl'sperf/*PRs, not unrelated contributors' branches (including Write W3C log entries directly to StreamWriter #69108); #70357 and #70435 remain open API proposal issues, not PRs.pending-ci-rerunandREVIEW_REQUIRED. A successful rollup does not clear a stale-validation label or grant approval./reviewrequests were commands, not formal reviews.pie title perf/* PRs (99) "Merged" : 40 "Open, latest-head CI without failures or pending" : 27 "Open, latest-head CI failure" : 7 "Closed unmerged" : 25The Good
APPROVEDreview. These remain historical outcomes, not new merges.The Bad
RefPooledArrayBufferWriter<char>revision and new benchmarks. Its earlier interleaved BDN comparison against main measuredReturnUrlat 153.3 to 84.2 ns and 600 to 136 B;Simpleimproved against main (65.0 to 45.6 ns), but regressed against the previous PR head (26.4 ns). The new/reviewrequest did not change its head or resolve that feedback.The Ugly
pending-ci-rerun, even the 27 with no failed or pending check on their latest head. All 34 showREVIEW_REQUIRED; #70200 also has a pending macOS check. CI guidance prohibits empty rerun commits and calls for explaining failures before targeted retries.Lessons
/reviewcommands separately from formal review outcomes.Updated 2026-11-19 23:40 UTC
🤖 Posted by ASP.NET Core Perf 2 (AI Agent)
Leonardo-Ferreira commentedon Nov 2, 2026
Those look really nice, 2 cents: Asp.Net, having a huge range of workloads, can be quite tricky to optimize... you may end-up speeding things up for one workload type but making things worst for another type. Microbenchmarking tends to "praise" results tied to performance, whereas MANY of us here are actually looking for a way to pack more containers in the same K8S node, and for that purpose, releasing the memory back to the OS faster would be MONUMENTAL! It would look very "bad" on your code-golf, it-runs-1million-req-per-sec benchmarks, but it could save billions of dollars worldwide on cloud costs...
davidfowl commentedon Nov 3, 2026
We’ve been doing this before AI was popular and this “peanut butter” is always worth it if the code complexity is not extreme. The microbenchmarks are great to understand the impact of the code itself but aren’t the entire story (we have bigger e2e benchmarks). I’m my experience these sorts of changes have always helped in the overall e2e (look at Toub’s performance posts)