NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #4099 most downloaded on npm
A WebAssembly implementation of xxHash
Last release 2 years ago
no release in 18 months
Ships fairly regularly
a new release about every 10 months
Nearly every release is documented
notes for 10 of 11 stable releases
Nothing withdrawn
no release was ever pulled
9 years old
11 releases · first in 2017
Cloudflare Workers disallow loading WebAssembly modules from an ArrayBuffer for security reasons.
Cloudflare Workers disallow loading WebAssembly modules from an ArrayBuffer for security reasons.
They support conditional import from the workerd field in package.json, therefore xxhash-wasm now includes an additional workerd package that includes the WASM in a separate file. (#51)
You can install it with npm as usual and import it with:
import xxhash from "xxhash-wasm";
.subarray() over .slice() to avoid unnecessary copy that will be discarded right afterwards (#52).subarray() over .slice() to avoid copy by @jungomi in https://github.com/jungomi/xxhash-wasm/pull/52Full Changelog: https://github.com/jungomi/xxhash-wasm/compare/v1.0.2...v1.1.0
One column per quarter.
Add support for Typescript's nodenext module resolution
nodenext module resolution (#33)Export data types separately + fixed bigint data type
To fully utilise the performance improvements, there are some breaking changes in the API and new engine requirements.
This big release includes an up to a 3-4x performance improvement in most cases and a new streaming API similar to Node's built-in crypto API. To fully utilise the performance improvements, there are some breaking changes in the API and new engine requirements.
To achieve these substantial performance improvements, a handful of new features have been used, which are fairly recent additions to the browsers, Node and the WebAssembly specification. These include the following:
BigInt support in WebAssemblyTextEncoder.encodeIntoTaking all of these requirements into account, v1.0.0 should be compatible with:
If support for an older engine is required, xxhash-wasm@0.4.2 is available with much broader engine support, but 3-4x slower hashing performance.
Besides the features regarding memory optimisations for WebAssembly, the biggest addition is the use of BigInt, which avoids the whole workaround that was previously used in order to represent u64 integers in JavaScript.
That makes everything a lot simpler and faster, but that also brings some breaking changes of the 64-bit API.
The TextEncoder.encodeInto allows encode the string as UTF-8 bytes directly into the WebAssembly memory, meaning that if you have the string and hash it directly, it will be faster than encoding it yourself and then using the Raw API.
If possible, defer the encoding of the string to the hashing, unless you need to use the encoded string (bytes) for other purposes as well, or you are creating the bytes differently (e.g. different encoding), in which case it's much more efficient to use the h**Raw APIs instead of having to unnecessarily convert them to a string first.
The streaming API allows to build up the input that is being hashed in an iterative manner, which is particularly helpful for larger inputs which are collected over time instead of having it all at once in memory.
It is kept in line with Node's crypto.createHash, hence the streams are initialised with create32/create64 and then .update(string | Uint8Array) is used to add an input, which can either be a string or a Uint8Array, and finally .digest() needs to be called to finalise the hash.
const { create32, create64 } = await xxhash();
// 32-bit version
create32()
.update("some data")
// update accepts either a string or Uint8Array
.update(Uint8Array.from([1, 2, 3]))
.digest(); // 955607085
// 64-bit version
create64()
.update("some data")
// update accepts either a string or Uint8Array
.update(Uint8Array.from([1, 2, 3]))
.digest(); // 883044157688673477n
BigInt64-bit hash APIs now use BigInt, where the seed is now a single BigInt instead of being split into the two halves seedHigh and seedLow.
This makes it much simpler to use and avoids any workarounds for previous limitations.
<table align="center"> <tbody> <tr> <th>0.4.2</th> <th>1.0.0</th> </tr> <tr valign="top"> <td>
h64(input: string, [seedHigh: u32, seedLow: u32]): string
h64Raw(input: Uint8Array, [seedHigh: u32, seedLow: u32]): Uint8Array
</td> <td>
h64(input: string, [seed: BigInt]): BigInt
h64ToString(input: string, [seed: BigInt]): string
h64Raw(input: Uint8Array, [seed: BigInt]): BigInt
</td> </tr> </tbody> </table>
h32/h64 return numbers instead of stringsThe hashes are numbers but were previously converted to a string of their a zero-padded hex string representations, mainly to keep the 32-bit in line with the 64-bit version, which could not be expressed by a single number without BigInt.
This overhead is unnecessary for many applications and therefore the performance suffers. Now h32 returns a number and h64 a BigInt.
For convenience, h32ToString and h64ToString have been added to get the hash as a string, which can also be achieved by converting them manually, e.g. hash64.toString(16).padStart(16, "0").
<table align="center"> <tbody> <tr> <th>0.4.2</th> <th>1.0.0</th> </tr> <tr valign="top"> <td>
h32(input: string, [seed: u32]): string
h64(input: string, [seedHigh: u32, seedLow: u32]): string
</td> <td>
h32(input: string, [seed: u32]): number
h64(input: string, [seed: BigInt]): BigInt
// New *ToString methods for convenience and to get old behaviour
h32ToString(input: string, [seed: u32]): string
h64ToString(input: string, [seed: BigInt]): string
</td> </tr> </tbody> </table>
Fix 64-bit hex representation when second part has leading zeros
- Initialise TextEncoder lazily
TextEncoder lazilyh32Raw and h64Raw APIs for use with Uint8Array
WebAssembly is optimised by binaryen:
WebAssembly is optimised by binaryen:
New API to avoid reinitialising WASM instances
New API to avoid reinitialising WASM instances
Include a CommonJS bundle for Node.js
Include a CommonJS bundle for Node.js
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →