EM Font Size Performance

Dean Wookey wookey.dean at gmail.com
Thu Apr 19 09:57:41 UTC 2018

Hi All,

In our application we add and remove a lot of nodes to the scene graph
regularly, and also make use of em font sizes to scale certain parts of our
application. We've noticed performance issues when adding nodes to the
scene, and it seems to be related to em sizes in our css.

As a test we added a chain of 20 stackpanes to a root stackpane. On the
root, we set a font size of 8pt via inline css. We then added and removed a
new tableview from the deepest stackpane 500 times, waiting for the node to
render after each add and remove.

In each of the experiments, we compared adding tableviews without css and
adding tableviews with an inline css font size of 8pt. We then tried
setting different font sizes in the stackpane chain.

I've attached sample code for these experiments.

The results (on jdk 9.0.4 - jdk 10 was similar) are as follows:

Setting a 1em font size on all stackpanes except the root.
With font on tableview: 14707ms
Without font on tableview: 27725ms

Setting a 1em font size on the first child of the root only.
With font on tableview: 14221ms
Without font on tableview: 19187ms

Using the original setup with no additional fonts.
With font on tableview: 13990ms
Without font on tableview: 13847ms

It looks like using a relative font size has a large effect performance
wise on descendant nodes. I would expect some amount of font size caching
in the chain of stackpanes since I'm reusing the same chain and
adding/removing nodes from that chain repeatedly.

I'm not sure how valid my test is, or how much of an issue this really is
in practice?


More information about the openjfx-dev mailing list