Skip to content

Make the UI rebuild only when the relevant data in PerAccountStore changes #1014

Closed as not planned
@sm-sayedi

Description

@sm-sayedi

Right now, we are rebuilding the UI based on the different settings (properties) of PerAccountStore, a ChangeNotifier injected into the widget tree through an InheritedNotifier widget.

I have noticed that unnecessary rebuilds often happen when a property of PerAccountStore changes, and because notifyListeners is called, all the registered build methods are called, even if they do not care about that specific property. I have examined this by putting some log statements in ComposeBox.build and _MessageListPageState.build methods both of which have a dependency on PerAccountStore by calling PerAccountStoreWidget.of(context). I then went to the web app and changed the time format settings for my account, which is PerAccountStore.userSettings in the codebase, a property that is not needed in the build methods mentioned above at the moment. This change of settings resulted in those unrelated build 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:

context.select<PerAccountStore, Map<int, User>>((store) => store.users);
context.select<PerAccountStore, UserSettings?>((store) => store.userSettings);

This will re-call the build methods only when the specified properties are changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-modelImplementing our data model (PerAccountStore, etc.)performanceSmooth and responsive UI; fixing jank, stutters, and lag

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions