#Method is performance heavy
64 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @nocturne atlas! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
have you tried using the debugger?
its the scaling of the image
how big are the images you are using?
trust me its the scaling. Try using Image.SCALE_FAST instead of Image_SCALE_SMOOTH
And how long does it take to execute?
it managed to decrease from 1.5s to 387ms
Also how often are you calling the method?
everytime you click a button that changes the displaying image
it really seems like the issue of the construcotr
why would it be the getProperty method tho
do you mind sharing what plugin you're using for the performance indications?
intellij profiler
it shouldn't really take so long at this point in the program. image#getProperty should returns almost immediately
How long is the execution time for loadImage ?
I haven't used the IntelliJ profiler myself so I can't tell you how you can measure a single method, sorry.
hm this method was written by someone else here i dont remember name, you sure this isnt causing the problem?
I wrote that method, that's why I suggested you use Image.Scale_Fast instead of Image.SCALE_SMOOTH
i see
The bottleneck is the image scaling
sorry i forgot your name lol
no worries
what about caching the already scaled images?
like storing them if they were already loaded?
yes
do i just store instance of Image returned by scaleImageKeepRatio
can i just compare them with .equals to check if its stored or theres better way?
and whenever you need the same image again, reuse it
create an array
use a map, mapping the filename or the original BufferedImage to the scaled instance
you have random indices anyways
so you can use the already existing indices
and just store the scaled images there
what if someone adds a new image into the directory
what would happen to imageFiles in that case?
youre correct now
nothing
since they're loaded at startup
ive implemented a simple caching and now its just this
but the second one is still taking some time as well
you could attempt to dirextly cache the ImageIcon objects instead
but is it really taking too long now?
I am again pleading for a Map:
Map<BufferedImage,BufferedImage> imageMap which maps the original image (the one that is loaded via ImageIO.read to it's scaled instance (created via the method).
new images can simply be added to the map and retrieving of scaled instances is realtively cheap.
why would you use BufferedImages as map keys?
the original non scaled image as the key, that retrieves the scaled instance
hashing and comparing images for looking up sounds like a waste of resources
just use the file name at that point
you could also use the filename
if a plain array isn't an option
but that could change.
nevermind i didn't read that
hashing images for that reason is stupid lol
yeah then a map is overkill
and the originql images would still need to be loaded