Skip to content

Commit 8130029

Browse files
authored
Use persistent hash map to store _inheritedWidgets (#107068)
* Use persistent hash map to store _inheritedWidgets Instead of using a HashMap and copying it down the tree which leads to quadratic time and space complexity use a persistent data structure which can amortize the cost by sharing parts of the structure. The data shows HAMT based PersistentHashMap to be 5-10x faster for building _inheritedWidgets and considerably more space effecient (e.g. bringing amount of memory allocated when constructing _inheritedWidgets in a tree with 150 InheritedWidget down to 70Kb from 970Kb). PersistentHashMap is slower than HashMap for access: 2-3x in relative terms, but in absolute terms we are only talking about ~0.2ns slow down per access and various app benchmarks we run have have not revealed any significant regressions.
1 parent 5b94f25 commit 8130029

File tree

4 files changed

+487
-8
lines changed

4 files changed

+487
-8
lines changed

packages/flutter/lib/foundation.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export 'src/foundation/math.dart';
3737
export 'src/foundation/node.dart';
3838
export 'src/foundation/object.dart';
3939
export 'src/foundation/observer_list.dart';
40+
export 'src/foundation/persistent_hash_map.dart';
4041
export 'src/foundation/platform.dart';
4142
export 'src/foundation/print.dart';
4243
export 'src/foundation/serialization.dart';

0 commit comments

Comments
 (0)