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

オープン
#44,333 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@microsoft-playwright-automation がすでに取り組んでいます。

2026年11月24日 から。

  • #44336 @microsoft-playwright-automation による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
100k
フォーク
6.9k
平均マージ
16時間 18分
マージ済み PR(30日)
281

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/playwright のほかの issue

microsoft/playwright の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。