I think I have found a bug, or at least I was surprised to realize that update on InheritedElement is implemented like:
@override
void update(covariant Component newComponent) {
final InheritedComponent oldComponent = component;
super.update(newComponent);
if (component.updateShouldNotify(oldComponent)) {
notifyClients(oldComponent);
}
// Rebuild to update the child widget tree (like Flutter's ProxyElement)
rebuild(); // <-- THIS IS THE PROBLEM
}
This caused me some performance problems. Still does, if I use the build-in theme detection of NoctermApp.
The Issue
rebuild() is called unconditionally after every update(), regardless of whether updateShouldNotify() returns true or false. This causes BuildableElement.performRebuild() to run, which calls updateChild() on the entire subtree.
Flutter's Approach
In Flutter, InheritedElement extends ProxyElement, which handles child updates more efficiently:
ProxyElement.update() directly calls updateChild() on the child
ProxyElement.performRebuild() only propagates to children if explicitly called
- The child element is updated in-place when widgets match, not rebuilt
I think I have found a bug, or at least I was surprised to realize that
updateonInheritedElementis implemented like:This caused me some performance problems. Still does, if I use the build-in theme detection of
NoctermApp.The Issue
rebuild()is called unconditionally after everyupdate(), regardless of whetherupdateShouldNotify()returns true or false. This causesBuildableElement.performRebuild()to run, which callsupdateChild()on the entire subtree.Flutter's Approach
In Flutter,
InheritedElementextendsProxyElement, which handles child updates more efficiently:ProxyElement.update()directly callsupdateChild()on the childProxyElement.performRebuild()only propagates to children if explicitly called