wyhash Explained: The Multiply-Mix Hash That Beat Them All

wyhash explained in plain terms means understanding the fast hash that beat them all with a single trick, a design from 2019 that multiplies two 64-bit words and folds the 128-bit product back on itself. The central question is why one multiplication can hash better than a whole chain of mixing steps, and the answer is that a full 128-bit product spreads every input bit across the whole output at once, so wyhash does in one instruction what older hashes did in many, and that economy is the whole point of the design.

wyhash is a fast non-cryptographic hash function created by Wang Yi with Diego Barrios Romero, Daniel Lemire and Li Jin, producing a 64-bit digest. It turns a message into a fingerprint by feeding its words through the MUM operation, a multiply followed by an xor of the two halves, and it is built on the idea that a hash should use the processor’s widest multiplication, which means the design leans on a single powerful instruction, and that focus is what makes it unlike the hashes of its era.

This article explains what wyhash is, how it works, and where it runs in the real world.

Key takeaways

  • wyhash is a fast hash from 2019, created by Wang Yi.
  • It produces a 64-bit digest from any input.
  • It is built on one operation: multiply, then fold.
  • It passed SMHasher, BigCrush and PractRand tests.
  • It is the default hash of the Nim, V and Zig languages.

What wyhash is

wyhash is a hash that turns a message into a fingerprint with a single repeated operation, and that simplicity is what makes it unusual among fast hashes. Each step multiplies two 64-bit words into a 128-bit product and xors the halves together, which means the mixing happens in one instruction, and because the operation is so cheap, the hash runs at the speed of the processor’s multiplier.

Its signature feature is the MUM operation. Most hashes mix with rotations, xors and additions in long chains, but wyhash multiplies and folds, which means every output bit depends on every input bit at once, and because the product is twice as wide as the inputs, the avalanche is stronger than a chain of small steps.

The design was a reaction to the slowness of the standard library. The hash functions shipped with most languages were decades old and slow, so Wang Yi built a hash that was both faster and better tested, because a hash table deserves a hash that keeps up, and that practicality is what made wyhash worth publishing.

It became one of the best-known fast hashes in the world, and it is named in every discussion of the field. wyhash is the default hash of the Nim, V and Zig programming languages, it is packed into Debian’s software sources, and it is still the first example engineers meet when they learn that multiplication can hash, which means the design survives as a tool even though newer hashes have arrived.

Its most famous property is its benchmark speed. In the SMHasher suite wyhash was the fastest hash tested, beating the standard library hash by nearly four times on large keys, which means the design won the speed race outright, and because that number was measured openly, the claim has never been in doubt.

Our guide to xxHash explains the earlier speed champion it overtook, and our guide to MurmurHash explains the older hash that defined the field.

How wyhash works

Everything starts with the seed and the secret, which initialise the mixing. wyhash xors the seed with the first words of a secret, which means the starting state depends on both, and because the secret is fixed by the version, the same input always gives the same hash under the same seed.

Each step begins with the input words, which are read eight bytes at a time. wyhash takes the next two 64-bit words of the message and xors them with the secret and the running state, which means fresh data arrives at every step, and because the words are wide, the hash absorbs data quickly.

The MUM operation is what makes the design work as a whole. The two words are multiplied into a 128-bit product, and the high and low halves are xored together, which means the value is scrambled thoroughly, and because the product carries every input bit into every output bit, the mixing is complete in a single step.

The parallel chains spread the effect further. For long inputs wyhash runs three chains at once, mixing different parts of the message independently, which means the processor’s pipelines stay busy, and because the chains only meet at the end, the hash uses the full width of a modern core.

The finalisation is what turns the state into a digest. After the last word, wyhash mixes the length and the remaining bytes into the state and runs the MUM operation once more, which means the digest depends on the whole message and nothing else, and because the final mix is the same as the mixing step, the design needs no special finishing step.

The digest comes from the final state, read out as a single 64-bit word. wyhash outputs the folded product directly as the fingerprint, which means the result is a fixed size whatever the input, and that size is exactly what a hash table or a database index needs for its lookup key.

A dark office desk with a laptop showing a glowing green cipher diagram, a brass key and a notebook beside it
A dark office desk with a laptop showing a glowing green cipher diagram, a brass key and a notebook beside it, shows how wyhash works: data words take turns being multiplied and folded, word after word, until a hash emerges.

Comparing wyhash with other fast hashes

wyhash is one of several fast hashes built for hash tables, and each was built with a different emphasis. xxHash is the earlier champion built on prime multiplication and rotation, MurmurHash is the older hash that defined the field, and wyhash is the one built on a single wide multiplication, while each approach trades something for something else.

The table below sets out the main contrasts between the leading approaches.

Aspect wyhash xxHash MurmurHash
Core operation Multiply and fold Multiply and rotate Multiply and xor-shift
Digest size 64 bits 32, 64 or 128 bits 32 or 128 bits
Seeded Yes, with a secret Yes, with a seed Yes, with a seed
Year 2019 2012 2008
Best for Fastest hash tables General hashing Legacy hash tables

The practical result is that wyhash is the right choice for fastest hash tables, xxHash suits general hashing, and MurmurHash fits legacy hash tables instead.

Where wyhash is used

Programming languages use it as their default hash. Nim, V and Zig all ship wyhash as the hash behind their hash tables, because it is fast and well tested, and that adoption is the reason wyhash runs in real programs rather than only in benchmarks.

Hash tables use it to spread keys with a wide fingerprint. A table that stores millions of keys wants a hash that is both fast and well distributed, because a slow hash becomes the bottleneck, and that speed is the reason wyhash earns its keep in language runtimes.

Databases use it to fingerprint records quickly. A database that hashes long strings needs a hash that processes big words, because a byte-at-a-time hash becomes the bottleneck, and that width is the reason wyhash appears in data systems.

Benchmarking uses it as a speed reference. Engineers still quote wyhash when they discuss how fast a hash can run, because it is the clearest example of multiplication-based mixing paying off, and that number shapes how new hashes are measured.

Teaching uses it as the MUM example. Courses introduce wyhash when they explain that one multiplication can hash, because it is the clearest case of the idea in a real design, and a student who understands wyhash understands why instruction choice matters in hash design.

Strengths and limits

The greatest strength of wyhash is its speed. A hash that beats the standard library by nearly four times gives programs faster tables for free, and that strength is real, measured in open benchmarks and confirmed by the languages that adopted it as their default.

It is also a strength that the design is thoroughly tested. wyhash passed SMHasher, PractRand and BigCrush, and that testing is worth more than cleverness in a field where a hash with a hidden bias is a hash that fails in production.

The limits are real, though, and the biggest is the zero-multiplication weakness. If the input words happen to match the secret, the product can be zero whatever the other word is, which means a crafted input can weaken the hash, and a system that faces hostile inputs must use a keyed hash with stronger guarantees instead.

wyhash checklist

  • Use wyhash for hash tables, never for security or passwords.
  • Remember it hashes with multiply-and-fold, not rotations.
  • Note the digest is 64 bits and the secret is fixed per version.
  • Compare it with xxHash to see two kinds of fast design.
  • Study the MUM operation, which is what mixes so well.
  • Check the version, since final version 4 is the current one.
  • Keep real digests behind standard hashes for signatures.
  • Read the 2019 paper to see how it was tested.
  • Choose a keyed hash when inputs may be hostile.

Frequently asked questions

What is wyhash in simple terms?

It is a 2019 fast hash that turns any input into a 64-bit fingerprint by multiplying pairs of words and folding the 128-bit products.

Who created wyhash?

Wang Yi, with Diego Barrios Romero, Daniel Lemire and Li Jin, who published it as a modern alternative to the old standard library hashes.

How is wyhash different from xxHash?

Both are fast 64-bit hashes, but wyhash mixes with a single wide multiplication while xxHash mixes with primes, rotations and avalanching.

Is wyhash still secure?

It is fast and well tested, but it is not a cryptographic hash, and crafted inputs can weaken it, so it must never guard secrets.

Where is wyhash used?

In the Nim, V and Zig languages, in hash tables, in databases, and in benchmarking of fast hashes.

When should I use wyhash?

When you need the fastest hash for a table, when your inputs are trusted, or when you study multiplication-based hashing.

The bottom line

wyhash explained in one line is this: the multiply-mix hash, a 2019 design that turned one wide multiplication into the fastest hash of its day and taught the field that a single instruction can hash.

It is proof that simplicity can beat complexity, and the reason it still matters is that every fast hash designed since has been judged partly by the lesson wyhash taught.

This article is general information about how wyhash works, not advice about choosing encryption for a particular device or system.

Latest articles

Scroll to Top