#FXML JavaFX Slowdowns

1 messages · Page 1 of 1 (latest)

keen lynx
#

Hey, I'm using fxml for javafx. im aware this causes slowdowns. However, some pages take way longer to load than others. Is there a reason why?
The page that takes longer to load only has two components but all other pages load very quickly yet they have more complicated fxml pages

junior quiverBOT
#

<@&987246487241105418> please have a look, thanks.

icy lily
#

using fxml isnt a bottleneck at all. its how you use it

#

theres a good chance your slowdowns could be caused by how your interface with FXML, or could be completely irrelevant to FXML

#

gotta see the code. more specifically, the code causing the problems

woven marten
#

Also wdym by slowdowns? You used a profiler to check?

keen lynx
keen lynx
#

The "Home" page takes 2-3 seconds to load, but other pages load quickly

#

Basically. I have a UI that is a border pane with navigation on the left and logo and whatever. Then I load a "page" and set it into the borderpane's center container when the navigation is interacted with

icy lily
keen lynx
#

Do you have any ideas of what might cause this?

icy lily
#

well id recommend cleaning up your code first

#

BaseUI has an FXMLLoader field which doesnt seem to be used

keen lynx
#

Yep I forgot that

icy lily
#

first step is simplifying the code as much as possible

#

next step would be pinpointing exactly where the time is being taken

#

are you sure its the loading of the homepage? maybe there are some other things going on causing a slowdown

#

so timing things would give you more insight into exactly what is taking so much time

keen lynx
#

Could it be that running it from the IDE would be slower than usual?

icy lily
#

throw in some simple timing systems

#
long start = System.nanoTime();
loadPage(...)
long end = System.nanoTime();
long timeTaken = end - start;```
#

itll give you a rough idea of how much time is being consumed relative to other things

keen lynx
#

Ok

#

Thats so weird

#

Ill try timing things inside of loadPage()

violet sage
#

but even then

#

it's not normal that it takes so much time

#

there must be something else causing problems

keen lynx
#

First time loaded

#

Second time loaded

#

Maybe I should try caching

icy lily
#

you should, but it also shouldnt be taking that long to reload the same thing

#

so theres something else going on

violet sage
keen lynx
#

Yeah im working on that

#

So the issue is with setCenter

#

Not load

#

The only differences between other pages and home is that Home is an HBox while the others are border panes

#

I would think that an HBox would be faster to put in

icy lily
violet sage
#

ah

#

hmm

icy lily
#

ima try to run this in about 10 mins

violet sage
#

try to verify that the dimension are exact so it doesn't need to resise anything

icy lily
#

that seems strange that setCenter would cause such a impact on load times

keen lynx
icy lily
#

the thing is, your controller does nothing, and the FXML is very simple

keen lynx
#

Maybe I need to remove whats already there?

#

Because its fast on the first setCenter

#

Is there a function for that

icy lily
#

i think it may be a different issue

keen lynx
#

When I paste the fxml contents of another page into the home page's fxml, it works fine

#

So its an issue with the contents of the home page's fxml but im not sure how to debug that

icy lily
keen lynx
#
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>

<HBox fillHeight="false" prefHeight="100.0" prefWidth="200.0" spacing="30.0" stylesheets="@../../../css/pages/home/home.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane prefHeight="200.0" prefWidth="200.0" styleClass="info_container">
         <children>
            <Text layoutX="84.0" layoutY="180.0" strokeType="OUTSIDE" strokeWidth="0.0" styleClass="info_title" text="# OUTFITS" />
            <Text layoutX="26.0" layoutY="111.0" strokeType="OUTSIDE" strokeWidth="0.0" styleClass="info_count" text="00" />
         </children>
      </AnchorPane>
      <AnchorPane prefHeight="200.0" prefWidth="200.0" styleClass="info_container">
         <children>
            <Text layoutX="99.0" layoutY="180.0" strokeType="OUTSIDE" strokeWidth="0.0" styleClass="info_title" text="# PIECES" />
            <Text layoutX="26.0" layoutY="111.0" strokeType="OUTSIDE" strokeWidth="0.0" styleClass="info_count" text="00" />
         </children>
      </AnchorPane>
   </children>
</HBox>
junior quiverBOT
violet sage
#

@keen lynx you could try to run a profiler to see what is actually taking time

icy lily
#

what does the stylesheet look like?

#

nothing in the FXML is suggesting high load times. and its strange that it loads quick the first time, but not the second

#

i dont think its the stylesheet causing the issues (although cant rule it out), i still think theres something else

#

but thats the only thing in that FXML that is suggesting time pitfalls

keen lynx
#
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Reddit+Mono:[email protected]&display=swap');


.info_container {
    -fx-effect: dropshadow(gaussian, rgba(157, 141, 195, 0.16), 30, 0, 10,10);
    -fx-background-color: linear-gradient(to bottom, #ffffff, #f1f7f8);

    -fx-background-radius: 7; /* Set the radius for the background */
    -fx-border-radius: 7; /* Set the radius for the border */
    -fx-border-color: #ffffff;
    -fx-border-width: 5px;
}

.info_title {
    -fx-font-family: "Poppins", monospace;
    -fx-font-size: 20px;
    -fx-font-weight: 900;
    -fx-fill: #636973;

}

.info_count {
    -fx-font-family: "Reddit Mono", monospace;
    -fx-font-size: 90px;
    -fx-font-weight: 500;
    -fx-fill: #40454c;
    -fx-effect: dropshadow(gaussian, rgba(114, 255, 180, 0.37), 0, 0.5, 5, 5);
}

junior quiverBOT
# keen lynx ``` @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,10...

Detected code, here are some useful tools:

Formatted code
@import
url('https : //fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Reddit+Mono:[email protected]&display=swap');
.info_container {
   - fx - effect : dropshadow(gaussian, rgba(157, 141, 195, 0.16), 30, 0, 10, 10);
   - fx - background - color : linear - gradient(to bottom, #ffffff, #f1f7f8);
   - fx - background - radius : 7;
  /* Set the radius for the background */
   -fx-border-radius: 7; /* Set the radius for the border */
   - fx - border - color : #ffffff;
   - fx - border - width : 5px;
}
.info_title {
   - fx - font - family : "Poppins", monospace;
   - fx - font - size : 20px;
   - fx - font - weight : 900;
   - fx - fill : #636973;
}
.info_count {
   - fx - font - family : "Reddit Mono", monospace;
   - fx - font - size : 90px;
   - fx - font - weight : 500;
   - fx - fill : #40454c;
   - fx - effect : dropshadow(gaussian, rgba(114, 255, 180, 0.37), 0, 0.5, 5, 5);
}
keen lynx
#

this is the stylesheet

icy lily
#

alright, so you are using a url to access a font

#

im not sure why that would take more time the 2nd occurrence

keen lynx
#

Yes but I am doing the same in all other stylesheets

#

This is so strange

icy lily
#

yeah, so probably not the issue

violet sage
#

well

#

remove it

#

just to be sure

keen lynx
#

Ok

violet sage
#

if the problem is still here, it's not that

keen lynx
#

still slow

icy lily
#

just seems strange that it would take longer the 2nd time

violet sage
#

but like I said, you should use a profiler, a profiler should be able to pin point what is exactly taking this much time

keen lynx
#

I kinda did a botchy profiler

#

Its slow at BorderPane.setCenter

icy lily
#

profiler isnt easy to comprehend though, they'd have to be able to analyze the results properly

#

otherwise they'd be confused on why byte[] is taking so much memory

violet sage
icy lily
#

when in reality, its because strings are backed by it

keen lynx
#

Wait

violet sage
keen lynx
#

youre RIGHT!

violet sage
#

?

keen lynx
#

The font was slowing it

icy lily
#

ayy

violet sage
#

ah?

violet sage
keen lynx
#

I removed the font from another file by accident and tested

#

Yes that was a mistake

#

I removed it from base.css instead of home.css

violet sage
#

but why only on second time?

keen lynx
#

Thats no longer my problem 😀

icy lily
#

lmfao

keen lynx
#

Maybe some sort of limit from the google api? IDK

icy lily
#

ima still try to troubleshoot

violet sage
#

can you try to make a Minimal reproducible example so we can find the problem?

#

still

icy lily
#

its still an interesting problem

keen lynx
#

Okay I will do that after I cook dinner then I will send a link here

#

Thank you

violet sage
icy lily
#

@violet sage

keen lynx
#

Whats an MRE

icy lily
#

Minimal Reproducable Example

keen lynx
#

Im a cs student with no practical experience guys

icy lily
#

the minimal code to reproduce the example

#

and even though this isnt minimal, its still not much

keen lynx
#

Will do

icy lily
#

so id consider it good enough for an MRE

icy lily