Skip to content

Use Marvin for CBOR map key hashing - #137264

Merged
rbhanda merged 2 commits into
dotnet:mainfrom
eiriktsarpalis:fix/cbor-hashcodes
Nov 11, 2026
Merged

rbhanda merged 2 commits into
dotnet:mainfrom
eiriktsarpalis:fix/cbor-hashcodes

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

Use the shared Marvin implementation instead of HashCode.AddBytes for CBOR map-key uniqueness checks. Remove the unused Microsoft.Bcl.HashCode dependency and its polyfill.

Validation

  • .\build.cmd clr+libs -rc Release -lc Release passed.
  • .\.dotnet\dotnet.exe build .\src\libraries\System.Formats.Cbor\src\System.Formats.Cbor.csproj -c Release /p:RuntimeConfiguration=Release passed for net12.0, net11.0, net10.0, netstandard2.0, and net462.
  • .\.dotnet\dotnet.exe build /t:test .\src\libraries\System.Formats.Cbor\tests\System.Formats.Cbor.Tests.csproj -c Release /p:RuntimeConfiguration=Release passed: 2,651 tests on .NET 12 and 2,605 on .NET Framework 4.8.1, with no failures or skips.

Performance

BenchmarkDotNet ShortRun on a Windows x64 Hyper-V VM (Xeon Platinum 8370C), using net11.0 CBOR assemblies on the locally built .NET 12 Release runtime. The benchmark reuses a reader to read 32-entry strict maps with byte-string keys and integer values.

Key length HashCode (us) Marvin (us) Ratio
4 bytes 1.914 1.692 0.88
16 bytes 1.890 1.832 0.97
128 bytes 2.841 3.383 1.19

Both versions reported 0 B allocated per operation. The 128-byte-key case is about 19% slower in this run. These are short-run measurements; the smaller differences should not be treated as conclusive speedups.

Note

This pull request description was generated with GitHub Copilot.

…lidation.

(cherry picked from commit 45617d8532217dedb5db9cf4975bd987e06fe31f)

Co-authored-by: Copilot <[email protected]>
Copilot-Session: f424924e-f7b6-4433-b707-17440b886781
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@rbhanda
rbhanda merged commit 2d3df99 into dotnet:main Nov 11, 2026
87 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants