Repository navigation
Support XXHash64, XXH3 and XXH128 on the web - #41
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo
|
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On the web,
XXHash64,XXH3andXXH128used to throwUnimplementedError. Their_32bitfiles are now real implementations that produce the same output as the 64-bit code. The public API is unchanged.lib/src/algorithms/xxh64/uint64_32bit.dartis a new helper for 64-bit arithmetic using two 32-bit halves. Multiplications are built from 16-bit pieces so every intermediate value stays below 2^53 and is exact on JS. Argon2's web path uses the same approach.xxh64_32bit.dart,xxh3_64_32bit.dartandxxh3_128_32bit.dartfollow their_64bitcounterparts step by step. The code the two XXH3 variants share is inxxh3_common_32bit.dart.AGENTS.mdnow describe web support. They note that seeds must fit in 53 bits on dart2js, and thatxxh64code/xxh3codecan round results above 2^53 there (*sum/hexgive exact values).This branch also contains an earlier, separate commit that syncs
AGENTS.mdwith the current platform dispatch and wasm CI setup.Tests
test/xxh_web_test.dartused to check that these throw. It now runs on every platform with 510 vectors from the reference C implementation (libxxhash 0.8.4, called through Pythonxxhash4.1.0). Each algorithm is tested with 5 web-safe seeds and 34 input lengths covering every short-input path, the long path and multi-block inputs. A streaming check is included. The generation script is recorded intest/fixures/xxh_vectors.dart.test/xxh_32bit_test.dart(vm-only):_32bitcode directly against the_64bitcode on random inputs, with full 64-bit seeds and custom secrets;Local results:
dart format --output=none --set-exit-if-changed .makes no changesdart analyze --fatal-infosreports no issuesdart test -p vm: all tests passdart test -p node: all tests passdart test -P wasm: all tests passdart test -p chrome test/xxh_web_test.dartpassesRough node throughput for 1 MiB inputs (dart2js -O2, single run in a cloud container, not the reference machine):
Findings not addressed here
Uint64List. If the secret's length isn't a multiple of 8, it throws on inputs over 240 bytes. The new 32-bit code reads the secret throughByteDataand matches the reference library, so the web now returns a correct hash where the VM throws. The fix is to read the secret throughByteDatain the_64bitfiles too.test/xxh3_test.dartare wrong. They cover a 147-byte secret at lengths 403, 512, 2048 and 2243.XXH3_64bits_withSecretfrom the reference library gives different values, which match the new 32-bit code. The correct values are intest/xxh_32bit_test.dartwith the method cited.xxh128code, which doesn't exist inlib/.No CHANGELOG entry: the version heading is left to the maintainer. Suggested bullet: "Support
XXHash64,XXH3andXXH128on the web via 32-bit implementations (previously threwUnimplementedError)".Generated by Claude Code