reapplyCss() Is called too many times when adding a node hierarchy to the Scene

David Grieve david.grieve at
Fri Mar 11 22:33:50 UTC 2016

There is (was?) some code in Node or Parent that was supposed to prevent 
Namely, I thought I had it so CSS was applied from the parent before 
applying to the children.

It may also depend on how you add the nodes to the scene.

On 3/11/16 5:18 PM, Scott Palmer wrote:
> I think I've discovered a significant performance issue with CSS
> processing...
> 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
>   -> invalidatedScenes
>       -> scenesChanged
>           -> setScenes    // on child Nodes -- recursion
>       -> impl_reapplyCSS()
>           ->reapplyCss()
>              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
> node hierarchy
> * 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.
> Scott

More information about the openjfx-dev mailing list