Back to Blog

Understanding the 3 Diff Engines

Understanding the 3 Diff Engines

Lastest ships with three distinct comparison modes: pixel diff for exact matching, structural diff for DOM-aware comparison, and perceptual diff for human-eye similarity scoring. Choosing the right engine depends on whether you need precision, flexibility, or tolerance for antialiasing and rendering variance.

Three stacked bands placing Lastest's diff engines on a strictness spectrum: Pixel (Pixelmatch) is strictest and catches OS noise, Structural (SSIM) catches layout shifts while ignoring font noise, Perceptual (Butteraugli) is most tolerant and catches real bugs while ignoring antialiasing.
The three engines form a single spectrum from strictest (Pixel) to most tolerant (Perceptual).

Pixel diff

The pixel diff engine compares screenshots byte-by-byte. If even a single pixel differs between the baseline and the new screenshot, it flags the change. This is the strictest mode and catches everything - including subpixel rendering differences across operating systems.

Best for: design systems, component libraries, and any context where pixel-perfect consistency matters.

Structural diff

The structural diff engine understands the DOM. Instead of comparing raw pixels, it compares the layout tree: element positions, sizes, visibility, and stacking order. This makes it tolerant of font rendering differences while still catching meaningful layout shifts.

Best for: responsive layouts, cross-browser testing, and catching layout regressions without false positives from text rendering.

Perceptual diff

The perceptual diff engine models human vision. It uses a perceptual color difference algorithm to score how visually similar two screenshots are, ignoring differences that a human wouldn't notice - like slight antialiasing variations or 1px shifts in shadow rendering.

Best for: end-to-end visual testing where you want to catch what users would actually see, not what a pixel counter would flag.

Decision flow: a baseline-vs-new screenshot pair enters a 'what matters for this test?' decision diamond that routes to Pixel for exact pixels, Structural for layout, or Perceptual for what users see, configurable per test or component.
What you care about for a given test decides which engine compares it, set per test or per component.

Combining engines

You can configure different diff engines per test or per component. A common pattern is to use pixel diff for your design system components and perceptual diff for full-page screenshots.

Two-column comparison: a red column running pixel diff on everything produces false positives from antialiasing and OS noise until the team auto-approves; a teal column matches the right engine per surface (Pixel for design system, Structural for responsive layout, Perceptual for full pages).
Using one blunt engine everywhere drowns real bugs in noise; matching the engine to each surface keeps the suite trustworthy.
tests:
  - name: "Button component"
    engine: pixel
    threshold: 0

  - name: "Dashboard page"
    engine: perceptual
    threshold: 0.02