Skip to content

Support XXHash64, XXH3 and XXH128 on the web - #41

Merged
dipu-bd merged 2 commits into
masterfrom
ccr-3e9bf447-zsxg7p
Nov 28, 2026
Merged

dipu-bd merged 2 commits into
masterfrom
ccr-3e9bf447-zsxg7p

Conversation

@dipu-bd

@dipu-bd dipu-bd commented Nov 28, 2026

Copy link
Copy Markdown
Member

Summary

On the web, XXHash64, XXH3 and XXH128 used to throw UnimplementedError. Their _32bit files 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.dart is 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.dart and xxh3_128_32bit.dart follow their _64bit counterparts step by step. The code the two XXH3 variants share is in xxh3_common_32bit.dart.
  • The class dartdocs, README and AGENTS.md now describe web support. They note that seeds must fit in 53 bits on dart2js, and that xxh64code/xxh3code can round results above 2^53 there (*sum/hex give exact values).

This branch also contains an earlier, separate commit that syncs AGENTS.md with the current platform dispatch and wasm CI setup.

Tests

  • test/xxh_web_test.dart used 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 Python xxhash 4.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 in test/fixures/xxh_vectors.dart.
  • test/xxh_32bit_test.dart (vm-only):
    • runs the _32bit code directly against the _64bit code on random inputs, with full 64-bit seeds and custom secrets;
    • checks the 32-bit code against the existing CSV fixtures;
    • checks long inputs with a 147-byte secret against reference values (see below).

Local results:

  • dart format --output=none --set-exit-if-changed . makes no changes
  • dart analyze --fatal-infos reports no issues
  • dart test -p vm: all tests pass
  • dart test -p node: all tests pass
  • dart test -P wasm: all tests pass
  • dart test -p chrome test/xxh_web_test.dart passes
  • the integration smoke test runs

Rough node throughput for 1 MiB inputs (dart2js -O2, single run in a cloud container, not the reference machine):

Algorithm Throughput
XXH64 ~77 MB/s
XXH3 / XXH128 ~49 MB/s
XXH32 (for comparison) ~79 MB/s

Findings not addressed here

  1. Some custom secrets crash on the VM. The 64-bit XXH3/XXH128 code views the secret as a 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 through ByteData and matches the reference library, so the web now returns a correct hash where the VM throws. The fix is to read the secret through ByteData in the _64bit files too.
  2. Four commented-out vectors in test/xxh3_test.dart are wrong. They cover a 147-byte secret at lengths 403, 512, 2048 and 2243. XXH3_64bits_withSecret from the reference library gives different values, which match the new 32-bit code. The correct values are in test/xxh_32bit_test.dart with the method cited.
  3. The README lists xxh128code, which doesn't exist in lib/.

No CHANGELOG entry: the version heading is left to the maintainer. Suggested bullet: "Support XXHash64, XXH3 and XXH128 on the web via 32-bit implementations (previously threw UnimplementedError)".


Generated by Claude Code

@codecov-commenter

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@dipu-bd
dipu-bd merged commit e3e54dd into master Nov 28, 2026
19 of 20 checks passed
@dipu-bd
dipu-bd deleted the ccr-3e9bf447-zsxg7p branch November 29, 2026 20:38
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.

3 participants