Skip to content
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

What's the complexity of dispatching updates in Provider? #329

Closed
PawlikMichal25 opened this issue Jan 26, 2020 · 4 comments
Closed

What's the complexity of dispatching updates in Provider? #329

PawlikMichal25 opened this issue Jan 26, 2020 · 4 comments

Comments

@PawlikMichal25
Copy link

What's the complexity of dispatching notifications to all consumers - in other words all Widgets calling Provider.of<T>, of a Provider<T> ?

So for example let's say we have one StreamProvider of String and N consumers of the String below it. What's then the complexity of dispatching updates to all consumers when there is a new value in a Stream?

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StreamProvider<String>.value(
      value: someStream,
      child: Column(  // There is in total N consumers of String in the subtree of this Column
        children: [
          Consumer<String>(...),
          Consumer<String>(...),
          Row(
            children: [
              Consumer<String>(...),
              Selector<String, bool>(...),
            ],
          ),
          ...,
          ...,
          ...,
          ProxyProvider<String, int>(...),
          Selector<String, bool>(...),
        ],
      ),
    );
  }
}

For comparison ChangeNotifier has a O(N²) complexity for this and I was curious what it is in case of Provider

@rrousselGit
Copy link
Owner

It's O(N), like with Inheritedwidget

And it's debounced.
Calling notifyListeners multiple times within the same frame will notify dependents only once.

@PawlikMichal25
Copy link
Author

That's great, thank you!

@canthelou-xyz
Copy link

Hi :)

So, is it best and simplier to have only one Provider for the whole app (instead of many for different features...) and only using Selector (instead of many Consumer or Provider.of) ?

@rrousselGit
Copy link
Owner

Having many providers is probably better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants