I have written the following demonstration program. Four HBox(s) containing one Text node each, are added to the root (Group). The first and last are animated with a timeli
Cache the node (doing this with your sample dropped the CPU usage from 100% of a core to 1%).
setCache(true);
setCacheShape(true);
setCacheHint(CacheHint.SPEED);
Read the javadoc on node caching.
Define your CSS rules in a stylesheet and not inline styles (if I recall that is more efficient due to the nature of the CSS implementation in JavaFX).
Take a look at performance tips and tricks on the open-jfx wiki.
Read related questions:
I expected the computations to be done in GPU instead.
JavaFX will do lots of computations on the GPU, however it does a tradeoff - some computations are better done on a CPU and JavaFX will use the CPU for these kinds of computations. Your issue is not one of having computations done on the GPU or CPU. Your issue is having too many computations done because appropriate caching hints have not been provided to the JavaFX system.
Is it considered a bad practice to use css to decorate nodes that are going to be animated?
Inline css styles are bad practice in general - put the css in a stylesheet. Using CSS on animated nodes is fine for most use cases.
Indeed setting setCache(true) and setCacheHint(CacheHint.SPEED) improved the animation but it is still laggy.
The animation does not lag on my machine, but then it is not really comparable because the hardware and software in my machine is from 2014, not 2008.
Perhaps try updating your graphics drivers and updating JavaFX to the latest development build.
Also, slow down the animation (e.g. give it a duration of five seconds rather than half a second). It can be hard to visually detect the smoothness of an animation when it moves very quickly.
Log a bug report in the JavaFX issue tracker - the JavaFX developers should be able to supply additional information on how to do turn on detailed JavaFX performance tracking which logs the rendering steps in the JavaFX pipeline and measures their performance on a frame by frame basis (I don't know how to do this).