-
Notifications
You must be signed in to change notification settings - Fork 61
Perf: Optimize Screenshot diff check #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perf: Optimize Screenshot diff check #271
Conversation
Replaces PNG encoding with raw RGBA bytes for the screenshot change detection. This avoids expensive PNG compression when checking if the screen has changed.
Introduces benchmark and validation tests for screenshot encoding and comparison. The benchmark test compares PNG and raw RGBA encoding speeds, while the validation test ensures raw RGBA bytes can accurately detect image differences.
|
@jeremiahseun mind adding a changelog entry under next? https://github.com/PostHog/posthog-flutter/blob/main/CHANGELOG.md#next |
marandaneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @jeremiahseun
Sure @marandaneto |
i think you can remove both |
|
@marandaneto I have updated the CHANGELOG and removed the test files. |
💡 Motivation and Context
This PR optimises the Session Replay screenshot capturing logic to reduce CPU usage and improve performance.
Previously, we were encoding the screen snapshot to PNG format before checking if the screen had actually changed. PNG encoding is a computationally expensive operation.
The Fix:
I switched the "diff check" logic to use
ui.ImageByteFormat.rawRgbainstead of PNG. The Raw RGBA format is significantly faster to generate as it requires no compression. We now only proceed to the expensive PNG encoding step after we have confirmed that the new frame is different from the previous one.This change avoids unnecessary PNG encoding cycles when the UI is static, leading to smoother app performance during recording.
💚 How did you test it?
I added two new test files to verify both the performance gain and the correctness of the implementation:
rawRgbabytes are identical for identical images and different for distinct images.📝 Checklist
Screenshots