Perf: Optimize Screenshot diff check#271
Merged
marandaneto merged 5 commits intoPostHog:mainfrom Feb 2, 2026
Merged
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.
marandaneto
reviewed
Jan 29, 2026
Member
|
@jeremiahseun mind adding a changelog entry under next? https://github.com/PostHog/posthog-flutter/blob/main/CHANGELOG.md#next |
Contributor
Author
Sure @marandaneto |
Member
i think you can remove both |
Contributor
Author
|
@marandaneto I have updated the CHANGELOG and removed the test files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 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