In #102336 we introduced the idea of the _UbiquitousInheritedWidget for Directionality which makes a tradeoff between faster build performance versus worse update performance. I think we should consider moving Theme over to UbiquitousInheritedWidget as well. All my other attempts to increase the speed of InheritedWidget have not panned out.
Reasons for migrating Theme:
Theme.of is the second most used caller of dependOnInheritedWidget in build_bench.dart
customer:money is seeing 16.7ms in Theme.of at startup, which isn't huge but is an easy win.
InheritedWidgets are consistently showing up as performance bottlenecks across different attempts to profile.
- Profiling Flutter Gallery and clicking through the Material pages also identified
Theme as the most used InheritedWidget.
Theme's scope is so large, that changing one thing will likely cause may widgets to reload anyway (lowering the price difference in the update algorithm)
- Theme data probably isn't changing all that often anyway.
My major misgiving about doing this though is that it would require making UbiquitousInheritedWidget part of the public API which might confuse authors of InheritedWidgets. I can't think of an alternative unless we wanted to duplicate the declaration. We could potentially transition it to a flag in InheritedWidget instead of a subclass. I'm not sure if that's more desirable.
What do you think @goderbauer @jonahwilliams ?
In #102336 we introduced the idea of the
_UbiquitousInheritedWidgetforDirectionalitywhich makes a tradeoff between faster build performance versus worse update performance. I think we should consider movingThemeover toUbiquitousInheritedWidgetas well. All my other attempts to increase the speed ofInheritedWidgethave not panned out.Reasons for migrating
Theme:Theme.ofis the second most used caller ofdependOnInheritedWidgetinbuild_bench.dartcustomer:moneyis seeing 16.7ms inTheme.ofat startup, which isn't huge but is an easy win.InheritedWidgets are consistently showing up as performance bottlenecks across different attempts to profile.Themeas the most used InheritedWidget.Theme's scope is so large, that changing one thing will likely cause may widgets to reload anyway (lowering the price difference in the update algorithm)My major misgiving about doing this though is that it would require making
UbiquitousInheritedWidgetpart of the public API which might confuse authors ofInheritedWidgets. I can't think of an alternative unless we wanted to duplicate the declaration. We could potentially transition it to a flag inInheritedWidgetinstead of a subclass. I'm not sure if that's more desirable.What do you think @goderbauer @jonahwilliams ?