chore: improve ImageAssert.AreSimilarAsync perf#22695
chore: improve ImageAssert.AreSimilarAsync perf#22695
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes the ImageAssert.AreSimilarAsync method by caching pixel values before performing calculations, reducing redundant indexer calls during image comparison. The RawBitmap indexer performs scaling calculations, array offset computation, and Color object construction, making repeated accesses expensive. By caching each pixel value once instead of accessing it three times, this change improves performance in a hot loop that processes every pixel in the image.
Changes:
- Cache
expected[x, y]andactual[x, y]pixel values before calculations - Use cached pixel values for RGB and alpha component calculations, reducing indexer calls from 6 to 2 per pixel
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22695/wasm-skia-net9/index.html |
349bbf1 to
e5f4427
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22695/wasm-skia-net9/index.html |
|
|
GitHub Issue: n/a
PR Type: 🔄 Refactoring (no functional changes, no api changes)
What is the current behavior? 🤔
What is the new behavior? 🚀
dont access the same pixel multiple times during ImageAssert.AreSimilarAsync