Thanks for the Answer Andy, I appreciate it.
1. Java 20.0.1 and JavaFX 20.0.2
2. I tried profiling the app, most of the time spent in loading a stage
is spent reading the FXML,
I tried removing all the logic inside the controllers and the
initialize() methods and the loading time does not change.
3. Yes, I tried using VisualVM and I noticed that the default GC (G1)
never returns memory to the OS even after a garbage collection.
I switched to ZGC and the it works much much better. My stage was
consuming up to 500MB of heap, switching to ZGC it consume up to 180MB,
don't ask me why, garbage collection is black magic for me.
I can say that most of my memory problems has been solved by switching
from G1 to ZGC garbage collector
but the loading time hasn't improved.
I have plenty of time to preload the FXML because my app starts with a
tray icon, and the user can click the tray
to open the settings if it needs it. The problem is that when the user
want to access the settings, loading that stage requires 1.8 seconds.
Doing this during the app startup:
log.info("Preloading settings fxml");
stage.setOpacity(0);
stage.show();
stage.close();
stage.setOpacity(1);
seems to help a lot in the loading time of the stage but it so ugly...
Davide
Il 26/08/2023 01:30, Andy Goryachev ha scritto:
1. which version of jdk/jfx are you using?
2. have you tried profiling your application during FXML loading?
3. have you tried looking at the heap allocation (using VisualVM or a
similar tool), to see where the bulk of memory consumption is?
-andy
*From: *Davide Perini <perini.dav...@dpsoftware.org>
*Date: *Friday, August 25, 2023 at 16:16
*To: *Andy Goryachev <andy.goryac...@oracle.com>,
openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
*Subject: *Re: [External] : Re: Preload fxml to avoid slow show()
I tried it, 99% of the heavy lift comes from FXML load.
I have 80Kb of FXML files, nothing particularly big,
I measured the laoding time on a 13900K CPU and it requires 1.8s.
Once loaded, I don't know how this is possible, my apps sucks 100MB
more RAM but after the first load,
opening/closing the tab pane is much faster.
I sincerely can't understand how a tabpane can suck 100MB od RAM and
how 80Kb of FXML can require almoast 2 seconds to load
on the world fastest consumer CPU (single thread).
I see that there are dozens of similar threads on the internet so this
should be a known problem
and at this point, I think that I'm out of luck.
Thank you anyway,
Davide
Il 25/08/2023 23:55, Andy Goryachev ha scritto:
Another suggestion might be to load tabs lazily. I don't think
FXML "pre-loading" is possible.
-andy
*From: *Davide Perini <perini.dav...@dpsoftware.org>
<mailto:perini.dav...@dpsoftware.org>
*Date: *Friday, August 25, 2023 at 14:31
*To: *Andy Goryachev <andy.goryac...@oracle.com>
<mailto:andy.goryac...@oracle.com>, openjfx-dev@openjdk.org
<openjfx-dev@openjdk.org> <mailto:openjfx-dev@openjdk.org>
*Subject: *[External] : Re: Preload fxml to avoid slow show()
My tab pane is very complex with a lot of tabs,
having an FXML is very welcomed.
Thanks
Davide
Il 25/08/2023 16:45, Andy Goryachev ha scritto:
You can try creating the scene graph programmatically, thus
avoiding FXML entirely.
-andy
*From: *openjfx-dev <openjfx-dev-r...@openjdk.org>
<mailto:openjfx-dev-r...@openjdk.org> on behalf of Davide
Perini <perini.dav...@dpsoftware.org>
<mailto:perini.dav...@dpsoftware.org>
*Date: *Friday, August 25, 2023 at 00:45
*To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
<mailto:openjfx-dev@openjdk.org>
*Subject: *Preload fxml to avoid slow show()
Hi,
I have a tabpane with 15 tabs, every tab has his own
controller and it's
pretty crowded.
On a 13900K CPU, show() method requires more than 750ms,
this feels laggy...
After the first show() call, loading the tab pane is much
faster...
Is there a way to "preload" an fxml?
I tried to show() and hide() it immediately and it seems to help,
but what is the best way to do it?
Thanks
Davide