Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Replace XxHash64 with System.IO.Hashing.Crc64 in Files class - #338

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/replace-xxhash64-with-crc64
Apr 27, 2026
Merged

Replace XxHash64 with System.IO.Hashing.Crc64 in Files class#338
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers/replace-xxhash64-with-crc64

Conversation

@jonathanpeppers

@jonathanpeppersjonathanpeppers commented Apr 23, 2026

Copy link
Copy Markdown
Member

Benchmark Results

MethodXxHash64 (before)Crc64 (after)SpeedupAlloc Delta
HashBytes46.00 us23.34 us~2x faster56 B -> 56 B
HashStream44.98 us23.07 us~2x faster184 B -> 120 B
HashFile75.83 us52.98 us~1.4x faster424 B -> 360 B
HasFileChanged163.23 us118.44 us~1.4x faster848 B -> 720 B

Changes

Replaced all XxHash64 usage in Files.cs with System.IO.Hashing.Crc64:

  • HashBytes -- XxHash64.Hash() to Crc64.Hash()
  • HashFile -- new XxHash64() to new Crc64()
  • HashStream -- new XxHash64() to new Crc64()
  • Renamed constant XXHASH64_SIZE_IN_BYTES to CRC64_SIZE_IN_BYTES

Used fully-qualified System.IO.Hashing.Crc64 to avoid ambiguity with the existing Crc64 : HashAlgorithm class in the same namespace (which uses a different CRC-64-Jones variant).

XorLength

Standard CRC64 maps all-zero inputs (of any length, including empty) to 0000000000000000. This caused a hash collision in HasBytesChanged when comparing an empty file against zero-filled byte arrays. To prevent this, we XOR the data length into the final hash -- the same technique the repo's custom Crc64 class uses in its HashFinal() method. This ensures that inputs with identical CRC values but different lengths produce distinct hashes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings April 23, 2026 16:07

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR replaces the hashing implementation in Files from XxHash64 to System.IO.Hashing.Crc64, while avoiding ambiguity with an existing Crc64 : HashAlgorithm type in the same namespace.

Changes:

  • Swapped XxHash64 usage to fully-qualified System.IO.Hashing.Crc64 in HashBytes, HashFile, and HashStream
  • Renamed the internal hash-size constant to CRC64_SIZE_IN_BYTES
  • Added inline notes clarifying the variant difference vs the repo’s existing Crc64 implementation

Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
Comment threadsrc/Microsoft.Android.Build.BaseTasks/Files.cs
@jonathanpeppers
jonathanpeppersforce-pushed the jonathanpeppers/replace-xxhash64-with-crc64 branch from 0f0cdc1 to 436f4b0CompareApril 23, 2026 16:17
@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) April 23, 2026 16:21
@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers
jonathanpeppersforce-pushed the jonathanpeppers/replace-xxhash64-with-crc64 branch from 436f4b0 to c8f6eb2CompareApril 23, 2026 16:28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppersforce-pushed the jonathanpeppers/replace-xxhash64-with-crc64 branch from c8f6eb2 to 8e423b4CompareApril 23, 2026 16:35
@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) April 23, 2026 17:43
@jonathanpeppersjonathanpeppers added the ready-to-review This PR is ready to review/merge. label Apr 23, 2026
@jonathanpeppers
jonathanpeppers merged commit 9e9d063 into mainApr 27, 2026
2 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers/replace-xxhash64-with-crc64 branch April 27, 2026 09:19
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-reviewThis PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jonathanpeppers@simonrozsival