Skip to content

refactor: simplify sharded KV using maphash.Comparable#23

Merged
chenyanchen merged 1 commit intomainfrom
fix/comparable-shared-cache
Jan 16, 2026
Merged

refactor: simplify sharded KV using maphash.Comparable#23
chenyanchen merged 1 commit intomainfrom
fix/comparable-shared-cache

Conversation

@chenyanchen
Copy link
Owner

Replace manual type-switch hashing with maphash.Comparable (Go 1.24), which correctly hashes any comparable type by value. This fixes a bug where struct keys were hashed by memory address instead of value.

  • Remove unsafe import and type-switch hashing logic
  • Remove nextPowerOf2 function and mask field (use modulo instead)
  • Add TestShardedKV_StructKey to verify struct keys work correctly
  • Update benchmarks in README

Replace manual type-switch hashing with maphash.Comparable (Go 1.24),
which correctly hashes any comparable type by value. This fixes a bug
where struct keys were hashed by memory address instead of value.

- Remove unsafe import and type-switch hashing logic
- Remove nextPowerOf2 function and mask field (use modulo instead)
- Add TestShardedKV_StructKey to verify struct keys work correctly
- Update benchmarks in README

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@chenyanchen chenyanchen self-assigned this Jan 16, 2026
@chenyanchen chenyanchen merged commit 3b41817 into main Jan 16, 2026
1 check passed
@chenyanchen chenyanchen deleted the fix/comparable-shared-cache branch January 16, 2026 03:33
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.

1 participant