npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@blazediff/core

v2.0.3

Published

Blazing-fast pixel-by-pixel image comparison. About 7x faster than pixelmatch, with the same output

Readme

@blazediff/core

npm bundle size NPM Downloads

High-performance pixel-by-pixel image comparison with a chunked, branch-free scan and YIQ perceptual color difference. About 7x faster than pixelmatch in total time across the benchmark fixtures, with the same counts and output bytes.

Features:

  • YIQ color space for perceptual color difference
  • Anti-aliasing detection and filtering
  • Chunked scan that skips identical and provably sub-threshold pixels with 32-bit integer tests
  • Support for alpha channel and transparency

For detailed algorithm explanation and mathematical formulas, see FORMULA.md.

Installation

npm install @blazediff/core

API

diff(a, b, options?)

Compares two RGBA images and returns a result object. a and b are { data, width, height }, where data is a Uint8Array, Uint8ClampedArray or Buffer of width * height * 4 bytes. Browser ImageData has this shape.

The result is one of two kinds:

type DiffResult =
  | { kind: "compared"; count: number; percentage: number; identical: boolean;
      window?: { x: number; y: number; count: number } }
  | { kind: "dimension-mismatch"; a: Size; b: Size };

count is the number of pixels that differ beyond threshold, after the mask and the anti-aliasing exclusion. With window, count stays the total and window gives the top-left corner and count of the busiest window. Images of different sizes return dimension-mismatch. Invalid buffers or options throw a BlazeDiffError with a code: invalid-image, invalid-output, invalid-mask or invalid-option.

Usage

import { diff } from "@blazediff/core";

const output = { data: new Uint8Array(width * height * 4), width, height };
const result = diff(a, b, { threshold: 0.1, output });

if (result.kind === "compared" && !result.identical) {
  console.log(`${result.count} pixels differ (${result.percentage.toFixed(2)}%)`);
}

// OKLab metric, a skipped region and the busiest 16×16 window.
const mask = new Uint8Array(width * height); // 1 = skip this pixel
const worst = diff(a, b, { metric: "oklab", mask, window: 16 });

Coming from pixelmatch

@blazediff/core/pixelmatch has the same signature, options, errors, counts and output bytes as pixelmatch 8.0.0. Change the import and nothing else:

import pixelmatch from "@blazediff/core/pixelmatch";

const count = pixelmatch(img1.data, img2.data, output, width, height, { threshold: 0.1 });

Algorithm

The default YIQ diff walks the image in chunks of 4096 pixels. Both inputs of a chunk fit the L1 cache. Each chunk narrows the work in steps:

  1. Identical chunks: In Node, a native Buffer compare skips chunks whose bytes are equal.
  2. Dirty groups: Groups of 4 pixels are tested as 32-bit words. A first pass drops the groups whose words agree on every bit that can matter at the threshold. A second pass keeps the groups with a pixel over the eigenvalue bound or a pixel that is not opaque.
  3. Candidates: The full YIQ metric runs on the dirty groups only. It is branch-free, because most differing pixels are noise and noise defeats branch prediction.
  4. Anti-aliasing: Only pixels over the threshold take the Vysniauskas (2009) check. Interior opaque pixels use exact integer luma keys.
  5. Output: The gray background comes from an exact integer-luma lookup table, with flat runs reused and long runs passed to the native fill. The few diff pixels are then drawn over it.

Steps 2 and 3 have no data-dependent branch, and the scratch lists are allocated once. OKLab, mask and window take separate loops that match pixelmatch 8.0.0. Counts and output bytes are the same as the previous release.

See FORMULA.md for detailed mathematical formulas and algorithm explanation.

Performance

Total: ~7.4x faster | Average: ~79% | Median: ~86% | With an output image: ~4.2x faster in total, ~66% average

Benchmarked against pixelmatch across 34 fixtures (50 iterations, 5 warmup) on Apple M1 Max with Node.js 22, count only. Full numbers in the root BENCHMARKS.md.

| Benchmark | Pixelmatch | BlazeDiff | Improvement | |-----------|------------|-----------|-------------| | 4k/1 (5600×3200) | 333.85ms | 41.73ms | 87.5% | | 4k/1 (identical) | 23.22ms | 3.31ms | 85.7% | | page/1 (3598×16384) | 148.48ms | 14.90ms | 90.0% | | page/1 (identical) | 69.44ms | 9.63ms | 86.1% | | small images | 0.07-12ms | 0.01-4.1ms | 38-88% |

The largest gains are on large images, where most pixels are identical or below the threshold. Small images with dense diffs gain the least.

References

  • Algorithm Documentation: FORMULA.md: mathematical foundation and formulas
  • YIQ Color Space: Kotsarenko & Ramos (2009) - "Measuring perceived color difference using YIQ NTSC transmission color space"
  • Anti-Aliasing Detection: Vysniauskas (2009) - "Anti-aliased Pixel and Intensity Slope Detector"
  • Inspiration: pixelmatch - Original pixel-by-pixel diff algorithm