-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Colored box optimization (#176028) #176073
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Code Review
This pull request introduces an optimization to ColoredBox by disabling anti-aliasing when drawing its background rectangle. This is a good change that should fix visual artifacts, such as seams between adjacent boxes. I've added one suggestion for a further performance improvement by caching the Paint object to avoid re-allocating it on every paint call.
| Paint() | ||
| ..color = color | ||
| ..isAntiAlias = false, |
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.
This is a good optimization. To further improve performance, consider caching the Paint object as a field in _RenderColoredBox to avoid allocating it on every paint call. The color can then be set on the cached Paint object before drawing.
For example:
class _RenderColoredBox extends RenderProxyBoxWithHitTestBehavior {
// ...
final Paint _paint = Paint()..isAntiAlias = false;
@override
void paint(PaintingContext context, Offset offset) {
// ...
if (size > Size.zero) {
_paint.color = color;
context.canvas.drawRect(offset & size, _paint);
}
// ...
}
}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.
I really wonder if there is a performance benefit here in real life or not. After seeing #171194 it always makes me nervous. Fine as-is though.
victorsanni
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.
Hi @definev, thanks for the PR. Could you add a test to make sure this change does not get regressed?
|
Hi @victorsanni, I created the test. Feel free to let me know if you’d like me to write more tests for it. This is my first time contributing to Flutter, thank you so much |
victorsanni
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.
This golden test in the rfw package is failing with the changes in this PR.
|
I think that’s the expected behavior since it changes the way ColoredBox is rendered. The next step I should take is to either regenerate all the golden tests or declare this as a breaking change that may affect existing golden tests? cc: @victorsanni |
|
@victorsanni @dkwingsmt Are there any new updates for me to do? |
victorsanni
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.
LGTM awaiting review from someone more knowledgeable about the subject such as @dkwingsmt.
For the failing customer test, the process is to disable it in a separate PR which will land before this one, then re-enable it after this PR lands while approving the new goldens. I can open a PR to do that.
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.
LGTM 👍 . I would guess that we were notting getting much benefit from setting isAntiAlias to true in this case, but I'm interested to see if the Google tests have any failures. We should watch out for any failures that appear to have benefitted from antialiasing.
And +1 to @dkwingsmt reviewing this as well.
| context.canvas.drawRect(offset & size, Paint()..color = color); | ||
| _paint.color = color; | ||
| context.canvas.drawRect(offset & size, _paint); |
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.
Can you instantiate the Paint here instead of reusing it each time? I avoid try to avoid this pattern after seeing #171194, even though that should be fixed by now.
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.
Sure, that my initial approach to. Seeing Gemini suggest reuse paint object so i change to fit it comment :-) Let reverse that
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.
Updated
| Paint() | ||
| ..color = color | ||
| ..isAntiAlias = false, |
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.
I really wonder if there is a performance benefit here in real life or not. After seeing #171194 it always makes me nervous. Fine as-is though.
|
Good find @dkwingsmt, I was worried something like that might happen. +1 to your recommendation of exploring exposing isAntiAlias. |
|
I think the effect should apply to all ColoredBox widgets since they depend on each other. For example, placing one anti-aliased ColoredBox between two non-anti-aliased ones still causes the visual bug to appear. We could introduce a new static variable in ColoredBox, called defaultIsAntiAlias, which would be set to true by default. However, users could set it to false if they prefer crisp borders. If we still want to expose it, let add a 'bool? isAntiAlias' and set it to defaultIsAntiAlias if null. |
65319cd to
e63e299
Compare
| } | ||
|
|
||
| @override | ||
| void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
| super.debugFillProperties(properties); | ||
| properties.add(DiagnosticsProperty<Color>('color', color)); | ||
| properties.add(DiagnosticsProperty<bool?>('isAntiAlias', isAntiAlias)); |
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.
Maybe defaultValue: true?
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.
This isn't fixed?
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.
I already fixed it
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.
I set default to true on constructor
|
@dkwingsmt i added the test but i don't know how to make it generate new golden test image and the CI is failing i don't know why. I follow the Writing-a-golden-file-test-for-package-flutter.md but seem i don't need to edit ci.yaml file |
|
The |
| /// The [ColoredBox.isAntiAlias] property. | ||
| /// |
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.
The macro already has the first paragraph.
| /// The [ColoredBox.isAntiAlias] property. | |
| /// |
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.
Done ✅
|
@definev Looks like there are still analyzer failures FYI. |
|
I will check on that |
|
I’ve fixed the format, but I haven’t found a way to resolve the Mac framework_tests_impeller and tree-status issues yet. |
Those are infra issues unrelated to this PR.
No, adding a golden test using |
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. 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. |
|
LGTM. Thank you for the contribution! |
|
autosubmit label was removed for flutter/flutter/176073, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
This PR fixed visual bug when placing multiple `ColoredBox`s together. (Fixes flutter#176028) ## 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]. - [x] 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. <!-- 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 --------- Co-authored-by: Victor Sanni <[email protected]>





This PR fixed visual bug when placing multiple
ColoredBoxs together. (Fixes #176028)Pre-launch Checklist
///).