Funkin icon indicating copy to clipboard operation
Funkin copied to clipboard

Fixed major memory usage issues

Open aiden3c opened this issue 3 years ago • 12 comments

When assets are loaded into the game, they are never unloaded. This can cause many issues related to significant RAM usage. Most issues that complain about characters loading as black boxes are from running out of memory. This also causes slowdowns as the system runs out of RAM. I found these issues myself playing the game normally for the first time, and it seems like a very critical issue. I'll note that in the cases where assets are loading as black boxes, that's more from devices with 4 gigs of RAM or so, so it may not be able to load the assets initially at all when loading the game. Because of that, this request may not fix all instances of black boxes from happening, but I think it'll help/prevent it in a lot of cases because it'll keep memory as low as it can.

Anyways, my solution overwrites the Haxe add command, and adds the object you're adding to an array of of tracked assets, then it loads the asset in as it would normally. Then in key areas (like when a song gets finished, or when going from a menu to a song), it'll unload the assets using the Haxe remove command. There are a few areas I manually unloaded some assets, like the GameOverSubstate, just because there's only one or two assets ever loaded.

TL;DR: This cleanly and dynamically keeps track of and removes unneeded assets to stop clogging up memory. This fixes some pretty significant issues.

(Memory usage outright) #856 #280 #58

(Black boxes/Characters just not loading) #1021 #992 (There are more I just don't want to search through it all lol)

Let me know if you have any questions or comments! Pretty happy with how clean the implementation is.

aiden3c avatar May 13 '21 00:05 aiden3c

raspi 4: My time has come

nickplj12 avatar May 13 '21 12:05 nickplj12

ninja, if u see this, merge or ur a poopy fart

insult of the year

nickplj12 avatar May 13 '21 14:05 nickplj12

i know im a baddie

hdboye avatar May 13 '21 14:05 hdboye

raspi 4: My time has come

I have a Raspberry Pi 4 (4GB RAM) and it would be cool to see the FPS on that thing, and play the game without squares

VMGuy23 avatar May 13 '21 16:05 VMGuy23

ninja, if u see this, merge or ur a poopy fart

hdboye when ninjamuffin doesn't merge this : https://youtu.be/EEuFbmmuqK4

trayfellow avatar May 15 '21 16:05 trayfellow

Sad, maybe it's works in desktop, but in mobile created crash.

R-code-0 avatar May 17 '21 12:05 R-code-0

Sad, maybe it's works in desktop, but in mobile created crash.

How did you go about compiling for mobile?

aiden3c avatar May 17 '21 14:05 aiden3c

what about the songs that get loaded in? from what i'm seeing they dont seem to be unloading

DuckBergen avatar May 17 '21 14:05 DuckBergen

actually since the game uses openfl libraries you could try to use the unloadLibrary() function of openfl.utils.Assets. i could make a proof of concept out of it

DuckBergen avatar May 18 '21 22:05 DuckBergen

Frankly, if you were to make a PoC then you may as well make an alternative PR with similar goals.

steviegt6 avatar May 20 '21 17:05 steviegt6

Frankly, if you were to make a PoC then you may as well make an alternative PR with similar goals.

i tried it! but unfourtanetly the results were dissapointing

basically what the function actually does is unload the library and it's paths, not unload the library from memory, which i find dissapointing

DuckBergen avatar May 23 '21 16:05 DuckBergen

Cool ass PR FR. Adding this shit in 👍

REALHaydenGaming avatar Sep 25 '22 21:09 REALHaydenGaming