Skip to content

Make Theme a UbiquitousInheritedWidget #102993

Description

@gaaclarke

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:

  1. Theme.of is the second most used caller of dependOnInheritedWidget in build_bench.dart
  2. customer:money is seeing 16.7ms in Theme.of at startup, which isn't huge but is an easy win.
  3. InheritedWidgets are consistently showing up as performance bottlenecks across different attempts to profile.
  4. Profiling Flutter Gallery and clicking through the Material pages also identified Theme as the most used InheritedWidget.
  5. 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)
  6. 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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions