reapplyCss() Is called too many times when adding a node hierarchy to the Scene
swpalmer at gmail.com
Fri Mar 11 22:18:56 UTC 2016
I think I've discovered a significant performance issue with CSS
Adding a Node hierarchy to a Scene leads to
javafx.scene.node.setScenes(Scene, SubScene) being called. This leads a
walk down the Node hierarchy like so:
-> setScenes // on child Nodes -- recursion
loops over children calling reapplyCss() on each - recursive
The thing to note there is:
* invalidatedScenes decides if it is going to call impl_reapplyCSS()
* invalidatedScenes calls scenesChanged which calls setScenes on all
children which leads to invalidateScenes being called recursively on the
* invalidatedScenes calls impl_reapplyCSS()
As the setScene call walks down the node hierarchy it gets to a leaf node
and then calls impl_reapplyCSS() which will call reapplyCss() recursively.
Since when reapplyCss() returns the cssFlag for the node will be set back
to UPDATE, so when the parent calls impl_reapplyCSS() the CSS is
recursively applied to the Nodes that just had CSS applied!
Am I missing something?
I made a quick test case where I add a VBox containing another VBox
containing a Rectangle to the Scene when I press a button. I can confirm
that reapplyCss() is called THREE times for the Rectangle, twice for the
"middle" VBox, and once on the "top" VBox.
Obviously the deeper the hierarchy the worse this gets.
More information about the openjfx-dev