Repository navigation
feat: target .NET 11 and speed up parsing with SearchValues - #103
Merged
Merged
Conversation
- Add net11.0 to the target frameworks and pin the .NET 11 SDK (11.0.100). - Pin LangVersion to C# 15 instead of preview. - Resolve Microsoft.Extensions.* per target framework (8.0.x, 9.0.23, 10.0.15, 11.0.0). On net11.0 the DI and caching abstractions ship with the shared framework, so the direct references are dropped there (NU1510). - Switch tests to xunit.v3.mtp-off, because coverlet.msbuild runs through VSTest, and write coverage per target framework. - Update test packages and analyzers (Roslynator 5, Meziantou 3, Roslyn 5.12). - Use StringComparer.Ordinal in telemetry assertions (new analyzer rule). - Remove BenchmarkDotNet.Diagnostics.Windows and NaughtyStrings, which are no longer referenced.
The solution now requires the .NET 11 SDK, so a per-runtime matrix can no longer build it with an older SDK. Install the 8, 9, 10 and 11 runtimes in one job and run the tests for every target framework there. Name the TRX files per test run so they no longer overwrite each other. The release workflow only pushes packages, so it only needs the .NET 11 SDK.
- GetRobot and GetMobileDevice (net9.0+) pre-filter groups of eight tokens
with SearchValues<string> (OrdinalIgnoreCase) and only run the per-token
check for groups that can match. Rule priority is preserved.
- HttpUserAgentStatics.Robots is a public, mutable array. Entries a caller
replaces at runtime are still checked in their original position.
- TryExtractVersion uses IndexOfAnyInRange / IndexOfAnyExcept instead of the
hand-written Vector128/Vector256 code. This also fixes the ARM64 path on
net8.0/net9.0, which read only the low byte of each char, so a character
such as U+0131 ('ı') was taken as the digit '1'.
- Remove VectorExtensions, which is no longer used.
The public API is unchanged. A differential run against the previous
implementation over 21,276 user agents showed no differences.
- HttpUserAgentParserBenchmarks measures one parse per user agent, with
current browser, crawler and unknown user agents as parameters.
- Setting BenchmarkBaselineAssembly to a previous build of the parser adds a
baseline benchmark through an extern alias.
- LibraryComparisonBenchmarks runs its ShortRun job in-process, because
BenchmarkDotNet 0.15.8 cannot build out-of-process jobs for .NET 11
("GetRuntimeVersion not implemented for NotRecognized").
- State the supported target frameworks and the required SDK. - Add the uncached parser comparison against the previous implementation and how to reproduce it. - Replace the .NET 10 library comparison with a .NET 11 run and a comparison table of the MyCSharp results.
gfoidl
approved these changes
Nov 22, 2026
gfoidl
left a comment
Contributor
There was a problem hiding this comment.
👍🏻 It's good to throw away the custom vectorized code and to rely on the BCL.
Although at the same time it's a pity because so lovely code is going away 😉.
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.
Summary
Adds .NET 11 as a target framework and makes uncached parsing 26–58% faster. Robot and mobile matching now use
SearchValues<string>, and the hand-written SIMD code for version extraction is replaced with framework span APIs. The public API and parsing results are unchanged.Performance
Uncached
Parse, current code against the parser from36ec145. Both ran on .NET 11.0.0 x64 (AMD Ryzen 9 9950X):Allocations are unchanged (0–40 B per parse). The README describes how to reproduce this.
Changes
Parser (
src/HttpUserAgentParser)SearchValues<string>withOrdinalIgnoreCase. A group is only checked token by token when its pre-filter matches, so rule priority stays the same.Robotsarray:HttpUserAgentStatics.Robotsis public and writable. Entries a caller replaces at runtime are still checked in their original position.GetRobot_UsesReplacementRuleInOriginalOrdercovers this.IndexOfAnyInRange('0', '9')plusIndexOfAnyExcept(SearchValues "0123456789.")replace the Vector128/Vector256 code.VectorExtensions.csis removed.Bug fix
On ARM64 under net8.0/net9.0, the old vector path narrowed chars with
AdvSimd.Arm64.UnzipEvenand kept only the low byte. It ran once the text after the browser token was at least 16 chars long. A non-ASCII char whose low byte is a digit, such ası(U+0131 →0x31), was then treated as part of the version. For example,Chrome/1.2ı3 followed by a long suffixreturned1.2ı3instead of1.2. x64 and net10.0+ used saturating narrowing and were not affected. This bug was found by reading the code and was not reproduced on ARM64 hardware.GetBrowser_ExtractsAsciiVersionnow pins the expected result on every platform.Build and dependencies
net8.0;net9.0;net10.0;net11.0. The SDK is pinned to11.0.100andLangVersionto15.0instead ofpreview.Microsoft.Extensions.*versions are now set per target framework (see Compatibility).xunit.v3.mtp-off, becausecoverlet.msbuildruns through VSTest. Coverage is written per target framework.BenchmarkDotNet.Diagnostics.WindowsandNaughtyStrings(no longer used).CI
dotnet testcovers every target framework.LogFilePrefix) so they no longer overwrite each other.Benchmarks
HttpUserAgentParserBenchmarksmeasures one parse per user agent, with current browser and crawler user agents as parameters.BenchmarkBaselineAssembly=<path>adds a baseline benchmark against an older build through anextern alias.LibraryComparisonBenchmarksruns in-process. BenchmarkDotNet 0.15.8 cannot build out-of-process jobs for .NET 11 (GetRuntimeVersion not implemented for NotRecognized), sojust benchcrashed there.Compatibility
ı/İ/ſ/Kelvin sign) and 20,000 random combinations.Microsoft.Extensions.*9.0.23 and 10.0.15. Until now every target framework referenced the 8.0.x versions. net8.0 stays on 8.0.x. On net11.0,MyCSharp.HttpUserAgentParserhas no NuGet dependencies, andMyCSharp.HttpUserAgentParser.MemoryCacheonly depends onMicrosoft.Extensions.Caching.Memory11.0.0.Verification
dotnet build -c Release: 0 warnings, 0 errorsdotnet test -c Release: all tests pass on net8.0, net9.0, net10.0 and net11.0 (214 / 13 / 10 per framework)dotnet pack: dependency groups per target framework checked in the nuspecNotes for reviewers
dotnet format --verify-no-changesreports findings inHttpContextExtensionsTests.csandHttpUserAgentParserMemoryCacheTelemetryTests.cs. Both already existed before this PR, and this PR doesn't touch those files.