Skip to content

Instantly share code, notes, and snippets.

@leafac
Created March 30, 2024 13:33
Show Gist options
  • Save leafac/3f12dd1bf5841bad59b10b93348d9dbc to your computer and use it in GitHub Desktop.
Save leafac/3f12dd1bf5841bad59b10b93348d9dbc to your computer and use it in GitHub Desktop.
  • Algorithms
    • xxHash: Self-proclaimed the fastest. (That’s my option)
    • djb2: Beautifully simple.
    • Murmur: Used by most other CSS-in-JS tools.
  • Uses by other related tools:
    • esbuild: xxHash & Boost’s hash_combine (not really sure which does which, but I feel xxHash is doing the file hashing).
    • styled-components: djb2
      • Progressive, which means the same hash is updated across elements that need to be hashed
        • Good: Remarkably simple.
        • Bad: The stability of the hashes depends upon the order of the hashed objects, and one removal in the middle affects all the subsequent hashes.
    • Emotion: murmur2
    • vanilla-extract: @emotion/hash & MD5
    • Linaria: murmur2
    • Compiled: murmur2
    • All of these implementations are only for strings, not for arbitrary binary data, which we need to do cache busting of images, for example.
  • xxHash Implementations for Node.js
    • All of them support Buffers (binary data and/or strings) & Streams.
    • Options below in order of popularity.
    • xxhashjs
      • Pure JavaScript (port).
      • Hasn’t been updated recently.
    • xxhash-wasm
      • Wasm
        • Maybe compiled from the canonical implementation, maybe hand-written?
      • Orders of magnitude faster than xxhashjs
      • Updated recently -xxhash
      • Node.js native module (old API) based on the canonical implementation.
      • Hasn’t been updated recently.
      • Annoying interface that requires a seed (which could be zero).
    • xxhash-addon (That’s my option)
      • Node.js native module (N-API) based on the canonical implementation.
      • Updated recently.
      • The only one to provide XXH3
    • https://github.com/bryc/code/tree/master/jshash/hashes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment