Skip to Content
New: codec-png-native and codec-png-wasm bring the blazediff-png codec to Node and WebAssembly, faster than spng and jSquash. Read more β†’
DocsPixelsπŸ†πŸ†πŸ† Node Native

Pixel-by-pixel Comparison with Node Native

@blazediff/core-native is the fastest way to diff two images from Node. It is the Rust core compiled to a Node addon through N-API, with SIMD in both passes. Unlike the JS and wasm cores it also handles the file layer: it accepts paths or encoded buffers, decodes PNG, JPEG and QOI itself, and writes the diff image to disk for you.

Reach for it in test runners and CI, which is where the decode cost and the per-run overhead actually add up. It needs a prebuilt binary for the platform, so it is not an option in browsers or on the edge. That is what the wasm build is for.

Installation

npm install @blazediff/core-native

Platform binaries ship as optional dependencies for macOS, Linux and Windows on x64 and arm64. There is no build step and no node-gyp.

Examples

Fixture A

Image 1

Fixture B

Image 2

Result

import { diff } from "@blazediff/core-native"; const result = await diff("3a.png", "3b.png"); if (result.kind === "compared") { if (result.identical) console.log("identical"); else console.log(`${result.count} pixels differ (${result.percentage.toFixed(2)}%)`); } else if (result.kind === "dimension-mismatch") { console.log("dimensions differ"); }

Encoded inputs are borrowed directly for each native call, so the JavaScript bytes are never copied into Rust. Decoding still allocates native RGBA buffers, and on a 4K pair that decode is the larger share of the total.

What it costs

Against odiffΒ  on the same fixtures with image IO included, measured with hyperfine on an M1 Max, 25 runs:

Caseodiff@blazediff/core-native
4K pair1157.12-1677.13ms288.01-349.43ms
4K pair, identical269.36-366.79ms183.94-230.29ms

That is 4x to 4.8x on a changed 4K pair. Because decode dominates end-to-end time, passing already-decoded buffers moves the number further than any change to the diff kernel would. Full tables.

Next

Last updated on