Skip to content

Conversation

@fzyzcjy
Copy link
Contributor

@fzyzcjy fzyzcjy commented Sep 16, 2022

How the bug is found

This bug is surely not found by human eyes reading each and every line of Flutter code :)

I proposed the idea that a linter can be created (dart-code-checker/dart-code-metrics#997) to validate whether RenderObject field setters have correct early-return code. @incendial implemented it and ran it (dart-code-checker/dart-code-metrics#1003).

Thus, thanks @incendial for implementing the linter and run it through flutter framework code!

Bug description

As we know, when implementing a setter in RenderObject, we usually early halt if the new value is equal to the old value (such as this one, indeed almost all fields in RenderObject child classes are examples). This is very necessary, because we are setting fields in updateRenderObject unconditionally. If we do not early return, we will execute the full logic like markNeedsPaint and so on unconditionally on every updateRenderObject. That will be performance penalty.

The current PR fixes one bug of such case. In more details, the viewController field setter lacks such early-return, and thus unconditionally calls markNeedsPaint. The setter is called from updateRenderObject as follows:

image

And _UiKitPlatformView is used here:

image

In other words, the controller is not changed in every frame. Instead, in common cases, it should be the same one for many frames. However, it triggers repaint for each and every rebuild.

Close #111788

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 16, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

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.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Sep 16, 2022

Test passes here.

image

Without the fix, test fails:

image
image

Comment on lines 323 to 329
set viewController(UiKitViewController viewController) {
assert(viewController != null);
if (_viewController == viewController) {
return;
}
final bool needsSemanticsUpdate = _viewController.id != viewController.id;
_viewController = viewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing code, because the local viewController is shadowing the getter viewController. Perhaps while you are here you could rename the parameter to something harmless like value?

Copy link
Contributor Author

@fzyzcjy fzyzcjy Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (in latest commit).

Btw this seems also commonly seen in flutter framework code (though I agree value is neater), such as:

image

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 17, 2022

auto label is removed for flutter/flutter, pr: 111790, due to - Please get at least one approved review if you are already a member or two member reviews if you are not a member before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 17, 2022

auto label is removed for flutter/flutter, pr: 111790, due to Validations Fail.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Sep 17, 2022

Oops seems to because need 2 approvals

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 19, 2022
@auto-submit auto-submit bot merged commit 4ead92c into flutter:master Sep 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 20, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UiKitView has buggy RenderObject

3 participants