-
Notifications
You must be signed in to change notification settings - Fork 171
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
Make the UI rebuild only when the relevant data in PerAccountStore
changes
#1014
Comments
Perhaps worth mentioning that the message-list page (or parts of it anyway) should be rebuilding with visible changes when the time-format setting is changed 🙂—I've just filed #1015 for that. |
This is purely a matter of performance, not correctness — the behavior is correct either way — so the best thing to do is a quantitative question of what gives the best performance, weighed against effects on the complexity of reading and writing the code. We already do as the issue title says for many types of updates. If you take a look at I'm content for us to rebuild the whole tree when one of the infrequent types of events happens, including
So I'll close this issue because I think we don't need to go farther in this direction than we have already. If at any point we find we have a performance issue in practice that's related to rebuilds, we'll want to investigate and resolve that. We can open a specific issue then. |
If we do see a rebuild-related performance problem in the future: in general, the canonical Flutter approach to that sort of problem is to arrange things so the build methods are cheap, more so than to try to prevent rebuilds — the Flutter architecture is that widgets generally may be rebuilt on every frame. Discussion in docs here, with more details: We do have a few known places in the app where the build methods are expensive. For example // TODO(perf) make an incrementally-updated view-model for InboxPage For any places do where we want to track more fine-grained data dependencies: while I wouldn't absolutely rule out
|
Right now, we are rebuilding the UI based on the different settings (properties) of
PerAccountStore
, aChangeNotifier
injected into the widget tree through anInheritedNotifier
widget.I have noticed that unnecessary rebuilds often happen when a property of
PerAccountStore
changes, and becausenotifyListeners
is called, all the registeredbuild
methods are called, even if they do not care about that specific property. I have examined this by putting somelog
statements inComposeBox.build
and_MessageListPageState.build
methods both of which have a dependency onPerAccountStore
by callingPerAccountStoreWidget.of(context)
. I then went to the web app and changed the time format settings for my account, which isPerAccountStore.userSettings
in the codebase, a property that is not needed in thebuild
methods mentioned above at the moment. This change of settings resulted in those unrelatedbuild
methods being called. There are numerous other places where such unnecessary rebuilds happen.We could implement this granular control of listening from scratch, or we can use a third-party package. One of those packages I would recommend is Provider. When using this package, we can do something like this:
This will re-call the
build
methods only when the specified properties are changed.The text was updated successfully, but these errors were encountered: