StreamBuilder updates' performance (One vs Multiple) StreamBuilder updates' performance (One vs Multiple) dart dart

StreamBuilder updates' performance (One vs Multiple)


Having more Listeners to the same Stream (or any other state) will decrease the performance.Check this benchmark when adding Listeners

value notifier benchmarks : https://github.com/knaeckeKami/changenotifier_benchmark

ChangeNotifier benchmarks : https://github.com/flutter/flutter/pull/62330

Having a list of expensive widgets with only one Listener will also decrease the performance (when they all get rebuild).

Anyways if you are using the same Stream with multiple children you should only use one Listener because when the state is changed they will all get a rebuild call whether they are on the same Listener or any of them have a Listener, but in the second case when the state is changed the Stream has to do more work notifying every Listener it has.

I got your problem, it occurs when you are having a list (of state) and yeah if you could have one Listener it would be faster for the notifying when the state changed but also it might be expansive to rebuild all the children which they don't have any update.

A solution for that case is using ScopedProvider form Riverpod which can be used with Stream or others state like StateNotifier, ChangeNotifier ...etc.