#Java application uses egregiously much RAM

1 messages · Page 1 of 1 (latest)

frail schooner
#

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

sweet lintelBOT
#

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

frail schooner
#

(the app has used up to 820 MB)

final sedge
#

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.

frail schooner
#

this is the information about one of the files. only a couple hundred bytes. does it... decompress when loaded as a bufferedimage?

wise sandal
#

820Mb of RAM usage you're saying?

frail schooner
#

appearantly

wise sandal
#

Bruh I wish lol.

final sedge
#

What's the resolution of that image?

frail schooner
#

all of them are kept between 32x32 to maybe like 48x48

#

tiny

quartz ice
#

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

wise sandal
#

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.

final sedge
#

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.

frail schooner
final sedge
#

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.

frail schooner
#

yes it's tile based

wise sandal
#

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.

hallow spindle
frail schooner
#

if anyone knows it, it's this guy

hallow spindle
frail schooner
#

im lowkey scared of you sometimes

frail schooner
hallow spindle
hallow spindle
frail schooner
#

that makes sense

hallow spindle
#

You always want better perfs

frail schooner
#

especially with videogames

hallow spindle
#

Unless you are already using too much ram

wise sandal
#

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).

hallow spindle
wise sandal
#

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.

hallow spindle
wise sandal
#

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.

hallow spindle