Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Add ParallelPixelProcessor using coroutines to multi-thread fuzzy bitmap comparisons#208

Merged
DanielJette merged 1 commit intomasterfrom
207-multithreading
Mar 23, 2021
Merged

Add ParallelPixelProcessor using coroutines to multi-thread fuzzy bitmap comparisons#208
DanielJette merged 1 commit intomasterfrom
207-multithreading

Conversation

@DanielJette
Copy link
Copy Markdown
Contributor

What does this change accomplish?

Resolves #207

How have you achieved it?

The primary change in this PR is the introduction of the ParallelPixelProcessor class. The design of ParallelPixelProcessor is such that it creates a coroutine dispatcher pool matching the number of processor cores available. For example, on a 4-core device, a pool of 4 coroutines will be used. Then, the baseline image is chunked up into equal sized pieces, one for each core. Each chunk is then processed in parallel. In this manner, a significant speedup is achieved. Even for single-core processing, this algorithm is more computationally efficient in that it preloads the images into memory, rather that reading pixels via nested for-loops.

Running on a 4-core emulator, yielded the following average improvements:

Original Code ParallelProcessor Difference
3723ms 783ms 4.75x faster

I have then refactored FuzzyCompare to make use of ParallelPixelProcessor.

Tophat instructions

The test setExactness in ScreenshotRuleExampleTests can demonstrate this change.
FuzzyCompareBitmapTest also can be used to test this.

Notice

This change must keep master in a shippable state; it may be shipped without further notice.

Copy link
Copy Markdown
Contributor

@jaredh jaredh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice perf improvement! 🏎

@DanielJette DanielJette merged commit 66d0b0d into master Mar 23, 2021
@DanielJette DanielJette deleted the 207-multithreading branch March 23, 2021 14:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-thread the comparison code

2 participants