[Feature]: Skip PNG decode and diff when a screenshot matches its baseline byte for byte

Aperta
#44,333 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@microsoft-playwright-automation ci sta già lavorando.

Dal 24/11/2026.

  • #44336 di @microsoft-playwright-automation — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start in packages/utils/comparators.ts at compareImages() and trace how toHaveScreenshot() calls it. Read the comparator unit tests and the existing implementation in PR #44325; this issue says that PR is ready and reopening it is the fastest path, so a newcomer should review rather than duplicate. Done means byte-equal buffers skip PNG decode, equal decoded pixels skip the diff, unknown comparator values still throw, and the screenshot comparator tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent-triage-done
Problem

compareImages() in packages/utils/comparators.ts decodes both images and runs the diff on every call, also when the two buffers are byte-equal. toHaveScreenshot() calls the comparator several times per assertion, and Chromium encodes the same pixels to the same bytes. Most matching assertions therefore decode two PNGs to find no difference.

This is the "do buffer comparison as a fast check before parsing png" item from https://github.com/microsoft/playwright/issues/27068#issuecomment-1741308597.

Measurements

Apple Silicon, Chromium headless shell, 1 worker, median of 5 alternating runs:

Case Now With a byte-equal check
One compare, same bytes, 1280×720 PNG 51.5 ms 0.001 ms
One compare, same pixels, different encoding 51.9 ms 48.6 ms
Suite: 30 tests, 120 matching toHaveScreenshot() 10.39 s 7.28 s
Proposed approach
  1. In compareImages(), return a match before decoding when actualBuffer.equals(expectedBuffer).
  2. After decoding, return a match before the diff when the sizes and pixel data are equal.
  3. Validate the comparator option first, so an unknown comparator still throws.

Already implemented and tested in #44325, which was closed only to file this issue first. This is a small, low-risk performance fix with no behavior change. Reopening #44325 is the fastest path; it is ready for review.

Lingua principale
TypeScript
Stelle
100k
Fork
6.9k
Merge medio
16h 18m
PR unite (30g)
281

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/playwright

Tutte le issue di microsoft/playwright

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.