fix(rendering): correct PerformanceOverlay optionsMask checks and add tests#174814
fix(rendering): correct PerformanceOverlay optionsMask checks and add tests#174814jihanurrahman33 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug in RenderPerformanceOverlay where bitwise OR was used instead of bitwise AND for checking the optionsMask, which could lead to incorrect intrinsic height calculation. The change is sound and the addition of tests is a great improvement. I've provided a suggestion to refactor the bitmask checking logic for better readability and another to expand the test coverage to include more combinations of the performance overlay options.
| if ((optionsMask & (1 << PerformanceOverlayOption.displayRasterizerStatistics.index)) != 0 || | ||
| (optionsMask & (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index)) != 0) { | ||
| result += kDefaultGraphHeight; | ||
| } | ||
| if ((optionsMask | (1 << PerformanceOverlayOption.displayEngineStatistics.index) > 0) || | ||
| (optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0)) { | ||
| if ((optionsMask & (1 << PerformanceOverlayOption.displayEngineStatistics.index)) != 0 || | ||
| (optionsMask & (1 << PerformanceOverlayOption.visualizeEngineStatistics.index)) != 0) { | ||
| result += kDefaultGraphHeight; | ||
| } |
There was a problem hiding this comment.
For improved readability and slightly better performance, you can combine the bitmasks for each graph type before checking against optionsMask. This avoids multiple bitwise operations within the if condition.1
const int rasterizerBits = (1 << PerformanceOverlayOption.displayRasterizerStatistics.index) |
(1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index);
if ((optionsMask & rasterizerBits) != 0) {
result += kDefaultGraphHeight;
}
const int engineBits = (1 << PerformanceOverlayOption.displayEngineStatistics.index) |
(1 << PerformanceOverlayOption.visualizeEngineStatistics.index);
if ((optionsMask & engineBits) != 0) {
result += kDefaultGraphHeight;
}Style Guide References
Footnotes
|
Thanks for the suggestion — updated the implementation to combine the bitmasks into rasterizerBits and engineBits and check against optionsMask (commit eb0b722). The tests still pass. Happy to expand coverage further if you want additional combinations. |
dkwingsmt
left a comment
There was a problem hiding this comment.
This was such a silly mistake. Thank you so much for catching it!
dkwingsmt
left a comment
There was a problem hiding this comment.
Fixed some analyzer issues for you
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍, thanks for catching this.
Looks like there is an analyzer failure, but it's just a formatting thing.
| final RenderPerformanceOverlay r = RenderPerformanceOverlay(); | ||
| expect(r.computeMinIntrinsicHeight(100.0), 0.0); | ||
|
|
||
| // One engine stat enabled |
There was a problem hiding this comment.
Nit: Period at the end of these comments.
|
@jihanurrahman33 Looks like the analyzer is failing. |
|
@jihanurrahman33 Friendly reminder on the analyzer failure. |
|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@jihanurrahman33 Do you still have time to fix the analyzer failure here? I'd love to land this and it's otherwise ready to go! |
|
Hey @jihanurrahman33 thanks for contributing! Would you like to continue working on this change? |
This re-stages the changes from #174814 That PR had some outstanding feedback to resolve, this is now done and we can get this change in, with thanks to @jihanurrahman33 ! From the original PR: > Fix bitmask checks in RenderPerformanceOverlay._intrinsicHeight: > > Use bitwise AND (&) and compare against 0 instead of bitwise OR (|). > This ensures the intrinsic height is 0 when no options are enabled, 80.0 for one graph, > and 160.0 when both rasterizer and engine graphs are enabled. > Add tests in rendering/performance_overlay_test.dart to verify intrinsic height for > various masks. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…182309) This re-stages the changes from flutter#174814 That PR had some outstanding feedback to resolve, this is now done and we can get this change in, with thanks to @jihanurrahman33 ! From the original PR: > Fix bitmask checks in RenderPerformanceOverlay._intrinsicHeight: > > Use bitwise AND (&) and compare against 0 instead of bitwise OR (|). > This ensures the intrinsic height is 0 when no options are enabled, 80.0 for one graph, > and 160.0 when both rasterizer and engine graphs are enabled. > Add tests in rendering/performance_overlay_test.dart to verify intrinsic height for > various masks. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…182309) This re-stages the changes from flutter#174814 That PR had some outstanding feedback to resolve, this is now done and we can get this change in, with thanks to @jihanurrahman33 ! From the original PR: > Fix bitmask checks in RenderPerformanceOverlay._intrinsicHeight: > > Use bitwise AND (&) and compare against 0 instead of bitwise OR (|). > This ensures the intrinsic height is 0 when no options are enabled, 80.0 for one graph, > and 160.0 when both rasterizer and engine graphs are enabled. > Add tests in rendering/performance_overlay_test.dart to verify intrinsic height for > various masks. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Fix bitmask checks in RenderPerformanceOverlay._intrinsicHeight:
&) and compare against 0 instead of bitwise OR (|).and 160.0 when both rasterizer and engine graphs are enabled.
Add tests in rendering/performance_overlay_test.dart to verify intrinsic height for
various masks.