Skip to content

Greatly improve Checksum performance#12444

Merged
DustinCampbell merged 9 commits intodotnet:mainfrom
DustinCampbell:checksum-diet
Nov 6, 2025
Merged

Greatly improve Checksum performance#12444
DustinCampbell merged 9 commits intodotnet:mainfrom
DustinCampbell:checksum-diet

Conversation

@DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Nov 4, 2025

Note

I had originally thought that this change would impact the VMR, but that turns out to not be the case. I had expected that the JSON serialization changes would need to be ported, but I had forgotten that the Razor SDK doesn't actually care about checksums. Instead, I validated that the Razor SDK builds fine with this changee.

This change brings work done in Roslyn awhile back to use XXHash128 rather than SHA256 for checksum calculation. With checksums only needing 128 bits, the Checksum type can be converted to a struct that contains a couple of Int64s.

As part of this change, I updated the TagHelperChecksumBenchmark and ran it with the current and new Checksums. The performance of creating checksums is an order of magnitude more efficient.

Old Checksum benchmark

BenchmarkDotNet=v0.13.5.2136-nightly, OS=Windows 11 (10.0.27975.984)
Unknown processor
.NET SDK=9.0.111
  [Host]     : .NET 9.0.11 (9.0.1125.51716), X64 RyuJIT AVX2
  Job-TVSTTM : .NET 9.0.11 (9.0.1125.51716), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method TagHelperSet Mean Error StdDev Median Min Max Code Size Gen0 Allocated
'Create Checksums' Legacy 7.906 ms 0.0544 ms 0.0454 ms 7.904 ms 7.843 ms 7.987 ms 41 B 2.0000 79.13 KB
'Create Checksums' BlazorServerApp 1.389 ms 0.0157 ms 0.0122 ms 1.388 ms 1.365 ms 1.409 ms 41 B - 12.38 KB
'Create Checksums' TelerikMvc 10.089 ms 0.2013 ms 0.5197 ms 9.930 ms 9.473 ms 11.847 ms 7,084 B 2.0000 72.8 KB

New Checksum benchmark

BenchmarkDotNet=v0.13.5.2136-nightly, OS=Windows 11 (10.0.27975.984)
Unknown processor
.NET SDK=9.0.111
  [Host]     : .NET 9.0.11 (9.0.1125.51716), X64 RyuJIT AVX2
  Job-MBNNCX : .NET 9.0.11 (9.0.1125.51716), X64 RyuJIT AVX2

InvocationCount=1  UnrollFactor=1  
Method TagHelperSet Mean Error StdDev Median Min Max Code Size Allocated
'Create Checksums' Legacy 761.7 μs 15.14 μs 22.66 μs 760.0 μs 732.3 μs 821.6 μs 41 B -
'Create Checksums' BlazorServerApp 127.3 μs 2.12 μs 1.65 μs 126.7 μs 126.0 μs 131.3 μs 41 B -
'Create Checksums' TelerikMvc 918.8 μs 18.05 μs 17.72 μs 917.5 μs 892.3 μs 952.8 μs 41 B -

CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2832100&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/685921
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2831447&view=results

There's also some clean up in this change to the compiler benchmark to read different sets of tag helpers from resources.
These were copied from Roslyn, which copied them from the .NET runtime to avoid taking a dependency on the System.IO.Hashing package.
XxHash128 is a much faster hashing algorithm. Plus, it only needs 128 bits, allowing Checksum to become just a couple of Int64s.
@DustinCampbell DustinCampbell requested a review from a team as a code owner November 4, 2025 22:08
@ToddGrun
Copy link
Contributor

ToddGrun commented Nov 4, 2025

This is awesome! Thanks!

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@DustinCampbell DustinCampbell changed the title Greatly improve Checksum performances Greatly improve Checksum performance Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants