Elements are bad

Elements are another instance (ha) of poor design choices in Flutter.

My understanding of Elements:

The Element Tree is responsible for communicating between the cheap configuration (Widgets) and expensive painting (Render Obects). Changes in UI are realized by first providing a changed Widget Tree. The Element Tree, in turn, updates or replaces expensive Render Objects by comparing new widgets to old elements.

Now here is the Problem: The Elements are simply Instances. While this is obvious as well as apparent from documentation, the implications of this fact have not been properly adopted in Flutter’s architecture.

There is no need for a seperate “Instance” (Element) Tree. None. The Widget Tree contains complete information about relation, and every necessary COMPARISON of old instances and new widgets can adequately happen inside the WIDGET TREE.

Rebuild is triggered for a widget subtree. Flutter goes through the old widget tree, compares old instances to the new widget tree and marks them either for “needs repositioning”, “needs repaint”(fields changed) or “needs destruction”. Naturally also creates new instances in appropriate positions.

“State” is now obsolete, since it is reflected in object fields, as is common practice for object-oriented languages.

Mind you that this creates exactly zero new overhead. Instances that can be reused are reused, new widgets are still compared to old instances to check whether render objects need to be repainted, destroyed or repositioned and now keys have also, naturally, become obsolete.

The Widget’s immutability is no strength. Instead it causes Awkwardness - change in the property of a widget (like the string of Text()) is expressed as creation of a new widget (not really aligned with user intent) and now efficient comparison of old and new objects has to be managed by a third actor - the accursed Element Tree is born.

Disagreement is welcome, but please respond to my arguments instead of resorting to insults. Much appreciated.

1 Like

This isn’t quite right.

The “widget tree” is a lie - you cannot traverse the “widget tree” without the element tree.

Feel free to try building your own ideal framework if you’d like! Flutter has a layered design - you can throw out our widget and element trees and build your own framework on top of the render tree.

2 Likes

Nooo, I’d rather you just improve the architecture of your program. Thanks