Skip to content

fix: Use GetStableHashCode16 instead of truncation#4102

Merged
miwarnec merged 2 commits intomasterfrom
UseGetStableHashCode16
Mar 26, 2026
Merged

fix: Use GetStableHashCode16 instead of truncation#4102
miwarnec merged 2 commits intomasterfrom
UseGetStableHashCode16

Conversation

@MrGadget1024
Copy link
Copy Markdown
Collaborator

GetStableHashCode16 uses XOR folding instead of truncation to reduce hash collisions, but we weren't using it everywhere.

  • Updated Weaver code in 3 places
  • Updated 3 weaver-called method signatures to ushort and removed casting
  • Changed delegate registration in RemoteCalls
  • Updated the GetDelegate test

Technical Justification

XOR folding preserves information from both halves of the 32-bit hash:
• Truncation example: 0x12345678 & 0xABCD5678 → both become 0x5678 ❌ Collision!
• XOR folding example:
• 0x12345678 → 0x1234 ^ 0x5678 = 0x444C
• 0xABCD5678 → 0xABCD ^ 0x5678 = 0xF9B5 ✅ Different results
This method is described in the official FNV documentation as the recommended approach for hash size reduction.

@MrGadget1024 MrGadget1024 requested a review from miwarnec March 26, 2026 06:57
@MrGadget1024 MrGadget1024 added bug Something isn't working Awaiting Review labels Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.56%. Comparing base (5537326) to head (b835daf).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4102   +/-   ##
=======================================
  Coverage   43.56%   43.56%           
=======================================
  Files         150      150           
  Lines       14626    14626           
=======================================
  Hits         6372     6372           
  Misses       8254     8254           
Flag Coverage Δ
unittests 43.56% <100.00%> (ø)
unity-6000.3.2f1 ?
unity-6000.4.0f1 43.56% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Mirror/Core/NetworkBehaviour.cs 85.71% <ø> (ø)
Assets/Mirror/Core/RemoteCalls.cs 90.24% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@miwarnec miwarnec merged commit 162c052 into master Mar 26, 2026
10 checks passed
@miwarnec miwarnec deleted the UseGetStableHashCode16 branch March 26, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting Review bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants