You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optimize unneeded rebuild when pushing overlay/navigator opaque content #45797
Currently, there's an optimization performed by Navigator/Overlay such that when a full-screen opaque content is placed above another content, the content behind will stop painting.
It is useful, but at the same time there's an irony:
The act of flagging the previously visible widget tree as no longer needing to be painted forces the entire associated widget tree to rebuild.
From my understanding, this is caused by a change in the depth of the associated widget tree during the transition. This, therefore, cause the widget tree to be deactivated and reactivated for a frame, which calls build/didChangeDependencies on everything.
It is suboptimal, especially considering the widget tree is actually no longer visible.
My theory is that is should be possible to fix this inconvenience by a change on this line
_Theatre(
// somehow make _RenderTheatre fill the gap of the missing Stack
onstage: onstageChildren.reversed.toList(growable:false),
offstage: offstageChildren,
);
This should remove the reparenting, which should no longer unnecessarily rebuild the no longer visible widget tree.
This is working as intended. In general, you should assume that all widgets can rebuild at any time, that they don't is mostly just an optimisation.
In particular, routes will rebuild because their navigator state has changed so they might need to update how they draw back buttons and the like.
I fix the "rebuild" problem by adding a key to Overlay build function.
First I add a GlobalKey to OverlayEntry class. For example _key2. This key will be used in TickerMode, the purpose is to give a Key to overlay offstage elements.
And then Flutter diff algorithm will know how to update offstage element properly, other than just inflateWidget. The inflateWidget method will reload images which were used in offstage elements, thus cause serious performance issue.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
SBDavid commentedon Dec 9, 2019
I fix the "rebuild" problem by adding a key to Overlay build function.
First I add a GlobalKey to
OverlayEntryclass. For example_key2. This key will be used inTickerMode, the purpose is to give a Key to overlay offstage elements.And the next step is add
_key2to build function.And then Flutter diff algorithm will know how to update offstage element properly, other than just inflateWidget. The inflateWidget method will reload images which were used in offstage elements, thus cause serious performance issue.
jkurtw commentedon Dec 13, 2019
b/146212303
liyuqian commentedon Dec 16, 2019
Is the code in #11655 (comment) also a reproduction for the issue here? If this issue has a significant performance impact, maybe it's nice to write a Flutter driver test (https://flutter.dev/docs/cookbook/testing/integration/profiling) so we can have some metrics to track.
goderbauer commentedon Jan 17, 2020
There's a fix out for review: #48900.
goderbauer commentedon Jan 22, 2020
As documented in the PR, this change had a positive affect on some of our transition benchmarks: #48900 (comment).
Thanks for the suggestion!
github-actions commentedon Aug 21, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.