-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Copied from PR
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:
And _UiKitPlatformView is used here:
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.

