[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-openjfx-dev
Subject: Re: [External] : Re: Preload fxml to avoid slow show()
From: Davide Perini <perini.davide () dpsoftware ! org>
Date: 2023-08-27 0:06:58
Message-ID: 6b08f9e0-907b-a62f-568c-a62f9c73a7e2 () dpsoftware ! org
[Download RAW message or body]
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.davide@dpsoftware.org>
> *Date: *Friday, August 25, 2023 at 16:16
> *To: *Andy Goryachev <andy.goryachev@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.davide@dpsoftware.org>
> <mailto:perini.davide@dpsoftware.org>
> *Date: *Friday, August 25, 2023 at 14:31
> *To: *Andy Goryachev <andy.goryachev@oracle.com>
> <mailto:andy.goryachev@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-retn@openjdk.org>
> <mailto:openjfx-dev-retn@openjdk.org> on behalf of Davide
> Perini <perini.davide@dpsoftware.org>
> <mailto:perini.davide@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
>
[Attachment #3 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Thanks for the Answer Andy, I appreciate it.<br>
<br>
1. Java 20.0.1 and JavaFX 20.0.2<br>
<br>
2. I tried profiling the app, most of the time spent in loading a
stage is spent reading the FXML,<br>
I tried removing all the logic inside the controllers and the
initialize() methods and the loading time does not change.<br>
<br>
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.<br>
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, <br>
don't ask me why, garbage collection is black magic for me.<br>
<br>
I can say that most of my memory problems has been solved by
switching from G1 to ZGC garbage collector <br>
but the loading time hasn't improved.<br>
<br>
I have plenty of time to preload the FXML because my app starts with
a tray icon, and the user can click the tray <br>
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.<br>
<br>
Doing this during the app startup:<br>
<div style="background-color:#1e1f22;color:#bcbec4">
<pre style="font-family:'JetBrains Mono',monospace;font-size:9,8pt;"><span \
style="color:#c77dbb;font-style:italic;">log</span>.info(<span \
style="color:#6aab73;">"Preloading settings fxml"</span>); <span \
style="color:#c77dbb;">stage</span>.setOpacity(<span \
style="color:#2aacb8;">0</span>); <span style="color:#c77dbb;">stage</span>.show();
<span style="color:#c77dbb;">stage</span>.close();
<span style="color:#c77dbb;">stage</span>.setOpacity(<span \
style="color:#2aacb8;">1</span>);</pre> </div>
seems to help a lot in the loading time of the stage but it so
ugly...<br>
<br>
Davide<br>
<br>
<br>
Il 26/08/2023 01:30, Andy Goryachev ha scritto:<br>
<blockquote type="cite"
cite="mid:DM5PR1001MB2172444E0E2530ED926468C7E5E3A@DM5PR1001MB2172.namprd10.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:"Yu Gothic";
panose-1:2 11 4 0 0 0 0 0 0 0;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:"Iosevka Fixed SS16";
panose-1:2 0 5 9 3 0 0 0 0 4;}@font-face
{font-family:"Times New Roman \(Body CS\)";
panose-1:2 11 6 4 2 2 2 2 2 4;}@font-face
{font-family:"Iosevka Fixed SS16 ";
panose-1:2 0 5 9 3 0 0 0 0 4;}@font-face
{font-family:"\@Yu Gothic";
panose-1:2 11 4 0 0 0 0 0 0 0;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Iosevka Fixed SS16";
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style>
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16"">1. which version of jdk/jfx are you \
using?<o:p></o:p></span></p> <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16"">2. have you tried profiling your application
during FXML loading?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16"">3. have you tried looking at the heap allocation
(using VisualVM or a similar tool), to see where the bulk of
memory consumption is?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16"">-andy<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16""><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span
style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Davide
Perini <a class="moz-txt-link-rfc2396E" \
href="mailto:perini.davide@dpsoftware.org"><perini.davide@dpsoftware.org></a><br>
<b>Date: </b>Friday, August 25, 2023 at 16:16<br>
<b>To: </b>Andy Goryachev
<a class="moz-txt-link-rfc2396E" \
href="mailto:andy.goryachev@oracle.com"><andy.goryachev@oracle.com></a>, <a \
class="moz-txt-link-abbreviated" \
href="mailto:openjfx-dev@openjdk.org">openjfx-dev@openjdk.org</a>
<a class="moz-txt-link-rfc2396E" \
href="mailto:openjfx-dev@openjdk.org"><openjfx-dev@openjdk.org></a><br> \
<b>Subject: </b>Re: [External] : Re: Preload fxml to avoid slow \
show()<o:p></o:p></span></p> </div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span
style="font-size:11.0pt">I tried it, 99% of the heavy lift
comes from FXML load.<br>
I have 80Kb of FXML files, nothing particularly big,<br>
I measured the laoding time on a 13900K CPU and it requires
1.8s.<br>
<br>
Once loaded, I don't know how this is possible, my apps
sucks 100MB more RAM but after the first load,<br>
opening/closing the tab pane is much faster.<br>
<br>
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<br>
on the world fastest consumer CPU (single thread).<br>
<br>
I see that there are dozens of similar threads on the
internet so this should be a known problem<br>
and at this point, I think that I'm out of luck.<br>
<br>
Thank you anyway,<br>
Davide<br>
<br>
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Il
25/08/2023 23:55, Andy Goryachev ha scritto:<o:p></o:p></span></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 "">Another suggestion might be to load tabs
lazily. I don't think FXML "pre-loading" is \
possible.</span><o:p></o:p></p> <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 "">-andy</span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span
style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Davide
Perini <a href="mailto:perini.davide@dpsoftware.org"
moz-do-not-send="true">
<perini.davide@dpsoftware.org></a><br>
<b>Date: </b>Friday, August 25, 2023 at 14:31<br>
<b>To: </b>Andy Goryachev <a
href="mailto:andy.goryachev@oracle.com"
moz-do-not-send="true"><andy.goryachev@oracle.com></a>,
<a href="mailto:openjfx-dev@openjdk.org"
moz-do-not-send="true" \
class="moz-txt-link-freetext">openjfx-dev@openjdk.org</a> <a \
href="mailto:openjfx-dev@openjdk.org" moz-do-not-send="true">
<openjfx-dev@openjdk.org></a><br>
<b>Subject: </b>[External] : Re: Preload fxml to avoid
slow show()</span><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span
style="font-size:11.0pt">My tab pane is very complex with
a lot of tabs,
<br>
having an FXML is very welcomed.<br>
<br>
Thanks<br>
Davide</span><o:p></o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Il
25/08/2023 16:45, Andy Goryachev ha scritto:</span><o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 "">You can try creating the scene graph
programmatically, thus avoiding FXML entirely.</span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 "">-andy</span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed
SS16 ""> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span
style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">openjfx-dev
<a href="mailto:openjfx-dev-retn@openjdk.org"
moz-do-not-send="true">
<openjfx-dev-retn@openjdk.org></a> on behalf
of Davide Perini <a
href="mailto:perini.davide@dpsoftware.org"
moz-do-not-send="true">
<perini.davide@dpsoftware.org></a><br>
<b>Date: </b>Friday, August 25, 2023 at 00:45<br>
<b>To: </b><a href="mailto:openjfx-dev@openjdk.org"
moz-do-not-send="true" \
class="moz-txt-link-freetext">openjfx-dev@openjdk.org</a> <a \
href="mailto:openjfx-dev@openjdk.org" moz-do-not-send="true">
<openjfx-dev@openjdk.org></a><br>
<b>Subject: </b>Preload fxml to avoid slow \
show()</span><o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi,<br>
I have a tabpane with 15 tabs, every tab has his own
controller and it's <br>
pretty crowded.<br>
<br>
On a 13900K CPU, show() method requires more than
750ms,<br>
this feels laggy...<br>
<br>
After the first show() call, loading the tab pane is
much faster...<br>
<br>
Is there a way to "preload" an fxml?<br>
<br>
I tried to show() and hide() it immediately and it
seems to help,<br>
but what is the best way to do it?<br>
<br>
Thanks<br>
Davide</span><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
</blockquote>
<br>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic