Repository navigation
Conversation
Combines the fast ticket deserialization (dotnet#70165) and serialization (dotnet#70172) paths while implementing the ticket and properties formats only once. BinaryPayloadReader/BinaryPayloadWriter either wrap a BinaryReader/BinaryWriter or read/write a buffer directly, and nested identities and claims dispatch to the protected virtuals when wrapping so derived serializers keep working. Co-authored-by: Copilot App <[email protected]>
- Use parameterless exception constructors for malformed payloads so the framework-localized default messages are used without formatting. - Exhaustively truncate a small representative ticket instead of the complex ticket containing a 20,000-character claim. - Keep TicketSerializer members in main's order, with each private dispatcher and core next to its virtual method. - Remove a duplicate benchmark ProjectReference and restore final newlines. Co-authored-by: Copilot App <[email protected]>
halter73
requested review from
Youssef1313,
cincuranet,
davpetr and
rokonec
as code owners
November 25, 2026 02:03
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Long strings ending in incomplete UTF-8 sequences decode differently from BinaryReader.ReadString, causing Deserialize and Read to restore inconsistent values and requiring a compatibility fix with parity tests.
1 open issue
What changed in this PR
This PR consolidates authentication ticket and properties serialization logic, combining the buffer optimizations from #70165 and #70172 while retaining virtual dispatch for derived serializers.
Changes:
- Adds buffer-backed readers and pooled writers to reduce default-path allocations.
- Shares format logic between buffer and stream paths without adding public API.
- Adds compatibility tests and benchmarks for default and derived serializers.
| File | Description |
|---|---|
src/Security/perf/Microbenchmarks/TicketSerializerBenchmark.cs |
Adds ticket and properties benchmarks, including derived ticket serializers. |
src/Security/Authentication/test/TicketSerializerTests.cs |
Adds wire-format, encoding, malformed-input, and override coverage. |
src/Security/Authentication/Core/src/TicketSerializer.cs |
Shares ticket format logic and introduces buffer fast paths. |
src/Security/Authentication/Core/src/PropertiesSerializer.cs |
Shares properties format logic and introduces buffer fast paths. |
src/Security/Authentication/Core/src/BinaryPayloadWriter.cs |
Adds pooled-buffer writing and a caller-provided writer adapter. |
src/Security/Authentication/Core/src/BinaryPayloadReader.cs |
Adds direct buffer reading and a caller-provided reader adapter. |
Review effort: Balanced
|
|
||
| public bool ReadBoolean() => _reader is not null ? _reader.ReadBoolean() : ReadByte() != 0; | ||
|
|
||
| public string ReadString() => _reader is not null ? _reader.ReadString() : Encoding.UTF8.GetString(ReadStringBytes()); |
This was referenced Nov 25, 2026
Member
|
/review |
This branch has not been deployed
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.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
b14765b213f1aec3cf8a9c2fe16b2880cb9189af↑ Interleaved measurements show lower allocations and faster default paths than main.
↓ Derived paths are slower in the mixed-use harness, though derived-only timings overlap; derived serialization allocates 16 B/op more under default JIT settings.
↓ Malformed-input exception types match, but messages differ; the follow-up incomplete-UTF-8 fix remains local and is not included in this revision.
Share ticket serialization format logic across buffer and virtual paths
Share ticket format logic while avoiding streams on the default paths.
Description
Combined replacement for #70165 (fast ticket deserialization) and #70172 (fast ticket serialization). Those PRs are referenced for context; neither branch is modified by this PR.
BinaryPayloadReaderandBinaryPayloadWriterare internal ref structs that either adapt a caller-providedBinaryReader/BinaryWriteror operate directly on a payload buffer. Ticket and properties format logic is implemented once, rather than duplicated between optimized and legacy paths. The default serializers bypass streams; derived serializers retain the virtual reader/writer methods and nested identity/claim dispatch, including caller-provided encoding. Counts are written before contents as on main, without backpatching. No new public API or assembly-access mechanism is introduced.Tests cover byte compatibility, overridden virtual methods, reader/writer encoding, null-argument parameter names, invalid UTF-8, malformed lengths and truncation. Malformed input preserves the tested exception types, not identical exception messages: the buffer reader uses parameterless exceptions instead of hand-written or interpolated English messages. Claim-string interning from #70165 is intentionally omitted. A local follow-up for incomplete UTF-8 compatibility is not included in this PR revision.
Measurements and tradeoffs
Baseline is main at
d848fbf2e3. We built each PR's serializer changes against that same base, and compared them with this PR's published head using frozen Release binaries. The Identity-cookie-shaped ticket in the custom harness was warmed up and measured over six process runs per implementation in alternating order, with fixed four-core affinity and high process priority. Allocation usesGC.GetAllocatedBytesForCurrentThread; timing usesStopwatch. These are exploratory custom-harness results, not BenchmarkDotNet results or performance guarantees.Default-path results retain the gains from both focused PRs, although #70165's hand-maintained claim-string cache reduces allocations further on deserialization. The combined PR omits that cache because it is a separate, read-only optimization with a manually maintained list; it could be evaluated independently.
Derived-path tradeoff: In the mixed-use harness, derived serialization and deserialization were slower for the combined implementation. The six-process median ranges were 1,720–2,113 ns on main vs. 2,092–2,618 ns combined for derived deserialize, and 1,203–1,319 ns vs. 1,372–1,584 ns for derived serialize. Derived serialization also allocated 16 B/op more. A separate derived-only run produced overlapping timings (deserialize 1,839 vs. 1,817 ns; serialize 1,237 vs. 1,262 ns), so the timing impact appears workload/JIT-profile dependent; its cause is not established. The focused PR implementations leave the legacy virtual path unchanged and did not show this combined-wrapper cost.
Limitations: a shared, loaded Windows VM; same-build timings varied, particularly for long-string cases; comparisons used a custom harness rather than BenchmarkDotNet. The PR variants were built by overlaying their serializer files on the common main base, not by benchmarking their live branches directly. Non-seekable streams were not separately tested. The full authentication suite was not run. The UTF-8 compatibility fix being explored locally has not been pushed or included in the measurements above.
Validation
After
. .\activate.ps1, with$env:ASPNETCORE_TEST_LOG_MAXPATH='32767':dotnet build src\Security\Authentication\Core\src\Microsoft.AspNetCore.Authentication.csproj -v q -nologo— passed, 0 warnings and 0 errors.dotnet test src\Security\Authentication\test\Microsoft.AspNetCore.Authentication.Test.csproj --filter "FullyQualifiedName~TicketSerializerTests" -p:UseIisNativeAssets=false -nologo— passed 22/22, none skipped.dotnet build src\Security\perf\Microbenchmarks\Microsoft.AspNetCore.Security.Microbenchmarks.csproj -c Release -p:UseIisNativeAssets=false— passed when preparing the baseline/candidate benchmark outputs.git diff --check d848fbf2e3 HEAD— passed.Related PRs: #70165 and #70172. This is a performance/consolidation change, not a bug-fix closing reference.