rrousselGit / state_notifier

ValueNotifier, but outside Flutter and with some extra perks
MIT License
311 stars 28 forks source link

Overhead in dispatching notifications with StateNotifier vs ValueNotifier #49

Closed Mabsten closed 3 years ago

Mabsten commented 3 years ago

The documentation of ChangeNotifier, of which 'ValueNotifier` is basically a simple variant (albeit with different practical uses), says that

It is O(1) for adding listeners and O(N) for removing listeners and dispatching notifications (where N is the number of listeners)"

The documentation of StateNotifier however asserts that

listeners cannot add extra listeners. This makes notifying listeners O(N) versus O(N²) for ValueNotifier

TL;DR: Notifying listeners with ValueNotifier is O(N²) (as stated by state_notifier Readme) or O(N) (as stated by ChangeNotifier doc) ?

In the second case, the two classes are equivalent in terms of notifying listeners overhead (obviously not with regard to removal listeners).

rrousselGit commented 3 years ago

The doc is outdated. ChangeNotifier was updated from O(N²) to O(N) some time ago, but the readme of state_notifier didn't follow

Mabsten commented 3 years ago

I got it. Thanks for the reply

rrousselGit commented 3 years ago

I have removed the mention, so I will close this.