Skip to content

Precision checking algorithm is very slow #573

Description

@fjcaetano

Describe the bug
When snapshot testing images with precision lower than 1, if the snapshots don't exactly match the reference images, the tests take much longer to run.

We currently have 66 snapshot tests in a framework

Precision Passing Tests Failing Tests Pixel-Imperfect Images Total Time
1 57 9 36 38s
0.97 66 0 36 483s

Those 9 failing unit-tests are recording 4 images each to account for different device sizes, so those 36 images that are not pixel-perfect are responsible for a 12.7x increase in the total duration for running 66 unit tests. The recorded images are not very large, ranging from 81KB to 255KB.

To Reproduce
Set the precision to any value lower than 1 and modify the tested view so they're not pixel-perfect with the reference images anymore.

Expected behavior
Checking whether or not the snapshots are within the accepted precision should be faster. A 12.7x increase for just 36 images is a whole different order of magnitude.

Environment

  • swift-snapshot-testing version 1.9.0
  • Xcode 13.2.1
  • Swift 5.5
  • iOS 15.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions