-
Notifications
You must be signed in to change notification settings - Fork 116
Hash small Uint8Arrays (≤128 bytes) by content rather than reference #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 157996e The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +152 B (+0.19%) Total Size: 80 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
324741e to
bee92ee
Compare
samwillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Just one comment on making a method public
| // @ts-expect-error - _writeByte is private but we need to use it here | ||
| hasher._writeByte(input[i]!) | ||
| } | ||
| return hasher.digest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make this method public rather than use the comment to ignore the type error.
Fixes `eq` function and hash indexing to compare Uint8Arrays/Buffers by content instead of reference, enabling proper ULID comparisons in WHERE clauses. Changes: - Hash small Uint8Arrays (≤128 bytes) by content in db-ivm for better indexing - Compare Uint8Arrays by content in eq operator via areValuesEqual() function - Add comprehensive tests for Uint8Array equality comparison
bee92ee to
421e32d
Compare
Add tests that specifically cover the user's reproduction case where Uint8Arrays are created with a length (e.g., new Uint8Array(5)) resulting in zero-filled arrays. Confirms that content comparison works correctly.
Add explicit tests for string and number equality to ensure that the areValuesEqual function doesn't break primitive comparisons. All tests pass, confirming the implementation correctly handles both Uint8Arrays and primitives.
Fixes function and hash indexing to compare Uint8Arrays/Buffers by content instead of reference, enabling proper ULID comparisons in WHERE clauses. The issue was that used which compares Uint8Arrays by reference. Now it uses which compares Uint8Arrays byte-by-byte. Changes: - Hash small Uint8Arrays (≤128 bytes) by content in db-ivm for better indexing - Compare Uint8Arrays by content in eq operator via areValuesEqual() function - Made writeByte() public in MurmurHashStream - Add comprehensive tests for Uint8Array equality comparison - Add integration test reproducing the user's exact scenario All tests pass (84/84 evaluator tests, 1/1 integration test).
Small Uint8Arrays (≤128 bytes) are now hashed by their content rather than by reference, enabling proper equality comparisons for binary IDs like ULIDs (16 bytes). Large arrays (>128 bytes) continue to be hashed by reference to avoid performance costs.
This allows the
eqexpression function to correctly compare binary IDs without forcing users to use the more expensive functional expression variant.Changes:
Fixes issue where binary ULIDs couldn't be compared using
eqdue to reference-based hashing.🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact