Skip to content
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

Improve performance by using the xxHash64 algorithm from the hash-wasm package #14

Closed
mrauhu opened this issue Jul 14, 2022 · 1 comment · May be fixed by #15
Closed

Improve performance by using the xxHash64 algorithm from the hash-wasm package #14

mrauhu opened this issue Jul 14, 2022 · 1 comment · May be fixed by #15

Comments

@mrauhu
Copy link

mrauhu commented Jul 14, 2022

Hello @pi0.

I suggest to use:

  • the xxHash64 algorithm instead of MurmurHash3 or SHA-256 algorithms;
  • WebAssembly version instead of JavaScript version.

Hash functions speed benchmark

Package and function Size
32 Bytes, MB/s 1 MB, MB/s
crypto-js 4.1.1 sha256 3.38 32.11
hash-wasm 4.9.0 sha256() 25.30 206.53
hash-wasm 4.9.0 createSHA256() 23.20 205.00
xxhash-wasm 0.4.2 21.80 9331.32
hash-wasm 4.9.0 xxhash64() 41.10 9639.89
hash-wasm 4.9.0 createXXHash64() 54.62 9946.82

CPU: Intel i7-8750H 2.2GHz (up to 3.9 GHz).

Information

Variants of breaking changes

Because createXXHash64() or xxHash64() functions is returns a promise.

A.

import { hash } from 'ohash';

const key = await hash(args);

B.

import { useHash } from 'ohash';

const hash = await useHash();
const key = hash(args);

Best wishes,
Sergey.

@pi0
Copy link
Member

pi0 commented Jul 14, 2022

Hi @mrauhu thanks for the suggestion and detailed explanation.

For the time being, i prefer to keep using sha256 for two reasons:

  • There is native API support both from node crypto and Web Crypto without the need to additional WASM to migrate
  • Sha algorithms are much more widely adopted and tested

Speed concerns can be addressed in the following significant hash versions by moving to use native implementation and as you mentioned promise API in order to leverage Web Crypto. BTW not set to stone. We might change the algorithm again and I will keep xxhash/hash-wasm in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants