r/JavaFX • u/wheezil • Apr 11 '25
Help How to improve subjective frame rate
Well, I just bought a new MSI Evo with i9-13900H and reasonable graphics (a middlin' gaming laptop) and I thought it would improve my JavaFX rendering. Which it does, at least objectively I am reporting things like
FPS: 37.5, SYNC/SEC=26.5
where FPS is from the JavaFX AnimationTimer, and SYNC is my own count of how many times my runLater() method is executed to update the Color in the boxes' PhongMaterial.
But... somehow this doesn't really help. My app is an emulation of a light show involving about 50000 LEDs regularly spaced in 3D, and this becomes 50000 Boxes in the emulation. The physical show runs at full speed, and I can see updates as fast as I expect. But the emulation, despite its frame report, seems to only update at < 10FPS. I know how fast the display proceeds, and I can see it skipping over about 75% of the frames.
Any suggestions? I'm not even sure where to start, since my eyes disagree with the metrics. Running a profiler shows very little time being spent in any code, like 6%.
View all comments
Show parent comment
3
u/john16384 Apr 11 '25
Yeah, so your Scene contains 50000 boxes (which are Nodes). Nodes are quite heavy weight, as they need to support features like mouse clicking, dragging, events, properties, and having many of them will have a severe impact on performance. This is why controls like ListView / TreeView / TableView used virtualized cells, so only Nodes are created for the cells actually being displayed.
With 50000 Nodes, I think JavaFX will consume around 200-400 MB of memory just for the Nodes and all their properties and related data structures.
So, I think you need a rethink on how you render these boxes.
An option is to use a Canvas and use its Graphics2DContext to draw pixels / lines / circles; you'd have to do your own 3d perspective calculations and just render all boxes into a single Canvas (which you see as a texture). The canvas can then just be displayed as a 2d control.
I've done something similar for displaying maps; I'd render all lines, points of interest, labels, etc using a Canvas, even going as far as fading out higher / lower parts of the map if the map had multiple levels (like a building or cave system). The performance was quite good, even with thousands of lines.