My java game is loading many images and sounds, so i was wondering if you guys can recommend me a simple to use profiler or just have some basic trouble shoot ideas. this is my resources directory, its a lot. I am loading in the files one by one, it would be better if i did a spritesheet wouldnt it
#Java application uses egregiously much RAM
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
(the app has used up to 820 MB)
Keep in mind that those images are a compressed format. If you load those images into a bitmap, they'll take up a lot more RAM. Games have to do image/texture/model juggling tricks all the time to manage this.
So what can i do to save RAM?
this is the information about one of the files. only a couple hundred bytes. does it... decompress when loaded as a bufferedimage?
820Mb of RAM usage you're saying?
appearantly
Bruh I wish lol.
What's the resolution of that image?
If you want to optimise your ram usage, you first need to figure out what's using up the ram. The best way is to take a heapdump of your app and open it in VisualVM
VisualVM is a great tool.
You can do a lot with it.
Some paid stuff out there too, but VisualVM is one of the best free options fs.
So that image is ~4KB for the pixels in RAM. And then you have any object overhead as well (each object has several bytes of overhead and each buffered-image probably has several objects internally). Larger images probably have even more impact (since some of that 529 bytes in the PNG is just image container overhead and not the image itself).
You can dynamically load and unload images (reading them in a background thread). This requires that the game have some prediction as to which image-sets are required when, and that the need for them is known early enough to pre-load them.
well a lot of stuff is random in this game, ill see. thanks anyway, i just started deleting some unused sfx and images
Otherwise reducing colour-depth, dropping alpha and reducing resolution are options.
If the images are the same size (tiles), it can be cheaper to load a tile-set as a single image and then paint/copy parts of it at a time.
I think you might benefit from only loading assets that are going to be used in the player's game environment. Like loading zones basically. You enter a dungeon, or level, or whatever, and only load the assets that are used in that area. Once an asset is no longer being used, you can unload it. Same for the items. Only load items the character is holding in their inv, or are on the drop tables or whatever for the enemies, or that will be found in that zone.
That's nothing
?
im lowkey scared of you sometimes
well you always know the answer like this wise turtle
You are trying to save ram when you don't have a ram problem at the first place
ye
Also note that this solution trade ram usage for loading time/worse performance
You either use less ram or have better performance
that makes sense
You always want better perfs
especially with videogames
Unless you are already using too much ram
Not necessarily, especially if he's doing zoning. Plus depending on the FPS he's already getting, no one needs 1k fps. That much overhead is useless (as an example).
the thing is that loading stuff dynamically would not reduce fps but rather introduce fps spikes or frame drops
Just fade to black or something if you hit a loading zone. Like a splash title in the new area to mask it. It wouldn't take long. Could just be an effect.
Unless the new area has tons of different assets, I don't see it being an issue.
It shouldn't affect performance very much. And if it does you could just keep all the common items/tiles/enemies/npcs loaded constantly.
That's static loading, and it still affect them, because it would decide how long loading screens can take
Looking at the game as it stands now, and just some educated guess work on where it'll be when it's finished; I don't think any of these approaches are going to tank the performance or be particularly jarring. He's not making anything 3D, it's 2D sprites that are all relatively light and small. I've loaded 4K+ assets before, and that takes time. This is not that.
If we were talking 1000s of assets, higher resolution, 3D models; that'd be different.
the same argument could be made for the ram used by those sprites, it doesn't matter, so nothing should be done