MIT licensed by Michael Chavinda
Maintained by [email protected]
This version can be pinned in stack with:snappy-hs-0.1.2.0@sha256:c3877c4ae400e3b024e8efc600b4867e218eeda86ce6788c91037f43eadd3bba,2349

Module documentation for 0.1.2.0

Used by 2 packages in nightly-2026-06-20(full list with versions):

snappy-hs

A pure Haskell implementation of the Snappy compression format.

This library prioritizes portability and simplicity over raw speed. It works reliably across platforms without requiring a C toolchain or dealing with FFI.

Performance

Measured against the native C library (the snappy bindings) on the Google Snappy test corpus, GHC 9.12 / aarch64, library built with -O2:

dataset (size) decompress vs C compress vs C
html (100 KB) 1.8x 2.3x
alice29.txt (149 KB) 1.5x 3.1x
geo.protodata (116 KB) 1.8x 2.4x
urls.10K (686 KB) 2.1x 2.6x
fireworks.jpeg (120 KB, incompressible) 1.0x 1.8x

Decompression runs at roughly C parity (~1-2x) and compression is ~2-3x of C. The gap that remains is GHC’s native code generator versus a C compiler, not the algorithm — the encoder mirrors C Snappy’s CompressFragment (skip heuristic, word-at-a-time match extension, input-sized hash table). Output is validated to be byte-compatible with the C library in both directions.

Reproduce with cabal bench (criterion, needs the C snappy library installed) or cabal run snappy-bench (pure, no C dependency).

When to use

  • You want cross-platform Snappy encode/decode with a pure Haskell dependency stack
  • You’d rather avoid C FFI and the build/packaging complexity that comes with it

When not to use

  • You need maximum throughput (use the native library or an FFI-based binding instead). You would get a lot of mileage from the library too however.

Changes

Revision history for snappy-hs

0.1.2.0 – 2026-06-19

  • Major throughput work bringing decompression to roughly C parity and compression to ~2–3x of C (was ~2–6x, and ~130x on incompressible data).
  • Encoder now follows C Snappy’s CompressFragment: an exponential skip heuristic over incompressible data, match chaining, word-at-a-time match extension via trailing-zero count, and an input-sized hash table (32-bit slots, capped at 2^14) instead of a fixed 256 KB table.
  • Decoder uses wide (8-byte) literal and overlapping-copy writes backed by output over-allocation slack.

0.1.0.5 – 2026-02-23

  • Use Ptr directly to make implementation faster.

0.1.0.4 – 2025-10-7

  • Loosen vector and bytestring bounds.

0.1.0.3 – 2025-08-30

  • Add home and issues page to hackage.

0.1.0.2 – 2025-08-18

  • Rename ParseException to DecodeError and expose its values.

0.1.0.1 – 2025-08-17

  • Loosen version bounds for bytestring and vector.

0.1.0.0 – 2025-08-16

  • Compress and decompress raw snappy