#FancyNameForUtilityMod - Significantly reduces memory use

1 messages · Page 1 of 1 (latest)

hollow plinth
#

I've been trying to workaround memory efficiency with the big "overpowered" mods like Cryptid and Jen's Almanac, and this is the best I came up with.
It'll probably earn you like... 3 or 4 times more "retriggers" on your jokers.
No promises that this doesn't break stuff, running GC in the middle of all your other shit might cause some issues.
But if it doesn't break stuff, then great.
Anyways, the testing I did was on a Mario multiplied up to 500000 retriggers, which didn't 2GB me. Without the mod, about 100000 retriggers (on a jimbo) would use up too much memory and crash.

(also, I didn't exactly check whether anyone's done this yet, it seems pretty easy but alas) (maybe not) (we can just delete this if its already a thing)
(don't tell anyone but this just runs the garbage collector when an event is added assuming memory usage is above 1gb and does nothing else)
#1283748709863002144 message

clear oasis
#

there's also some way to allow luajit to use practically unlimited memory (low 47-bit space), it's called GC64. There should be some way to make love use it, but I think it requires a custom compiled luajit binary

hollow plinth
#

got 1 million retriggers to work

#

2 million crashed

hard anvil
#

dang, less crashes?

clear oasis
#

clearly Balatro doesn't use GC64 though

hard anvil
#

suggest that balatro updates to 2.1?? o-o or am i just really stoopid

hollow plinth
#

it might be as simple as just replacing the lua51 dll

#

but probably not

tardy marten
#

you are not the first one to think that

hollow plinth
#

yeah figured

#

what does happen when you try that

#

just doesn't compile ?

tardy marten
#

thunk tried luajit 2.1 himself in 1.0.1 but game performed much worse

#

then modders tried to do it

#

same thing

#

¯_(ツ)_/¯

hollow plinth
#

luajit in general is sucky performance wise isn't it

hard anvil
#

dang, weird

hollow plinth
#

yeah i get why gc64 would hurt performance but severely killing it does seem odd

hollow plinth
#

anyways i figure ill just try gc64 every month until performance is okay

hard anvil
#

gl

hard anvil
#

How do you even update some things like this?

hollow plinth
#

well, this isn't something that'd need an update

#

it's like... 15 lines of code
if there's anything wrong with it it'd be a fundamental issue that can't be fixed regardless

#

if i made something significant yeah then id put it on github and make updates to it as needed

hard anvil
#

hmm okey's

#

ty

hollow plinth
#

so anyways there was a fixable non fundamental issue

#

and now i need to release an updated version

hard anvil
hard anvil
#

couldn;t you just? add 0's (ik i am stupid, i'll shut up now)

clear oasis
hard anvil
#

hmm

#

and changing the 1 >2 also doesn;t make the game better since we have 2 gb then and not 1?

clear oasis
#

no, using less memory is good

#

if we're actively using more than 1gb, there might be nothing to garbage collect and at worst we do nothing

#

if we set the limit to 2gb, the game has already crashed by the time we hit that threshold

#

one could try and see if further reducing the limit is beneficial, but I assume it makes no difference as you're not really interested in saving more memory if you've got plenty of space left

#

in fact it might be less efficient

hard anvil
#

hmm alright

#

just was trying to understand :)

clever rover
#

I've tried turning up the soft memory limit (to give more headroom for all my mods) and increased the GC's time budget

Think the effects are essentially placebo so far

#

Also probably should try patching the nuGC in functions/misc_functions.lua method instead of (or in addition to) inserting your own source of GC calls

#

djynasty has been investigating Balatro's memory leakage

glacial kettle
#

I haven’t looked at this mod — maybe there’s some befits to modded balatro, but I would be surprised if this has any significant effect on the vanilla game issues.

#

Honestly, I think that it’s kind of on the mod creators to optimise their mods if they are introducing a large number of retriggers. There comes a point where you can’t rely on the standard “retrigger” mechanic in the game.

clever rover
#

How does steamodded do in this regard? IIRC it has APIs for a lot of things including retriggers

tardy marten
#

the added retriggers API is not any more optimized than it was in cryptid, as far as I know

hollow plinth
#

the ver i posted doesnt work rn btw

#
local inityet = false
local oldlocalize
local oldeval
local localizations = 0
local waitforotheroverrides = 0

local oldupd = G.update
G.update = function(self, dt)
    oldupd(self, dt)
    if not inityet then
        if localize and eval_card then
            waitforotheroverrides = waitforotheroverrides + 1
            if waitforotheroverrides == 120 then
                oldeval = eval_card
                eval_card = function(a,b)
                    collectgarbage("collect")
                    return oldeval(a,b)
                end
                inityet = true
                oldlocalize = localize
                localize = function(a,b,c)
                    if localizations%1000 < 1 then  
                        collectgarbage("collect")
                    end
                    localizations = localizations + 1
                    return oldlocalize(a,b,c)
                end
            end
        end
    end
end

this works much better
collectgarbage("count") is unreliable

#

ofc this isnt good on performance but

#

thats not what im trying to optimize here

#

the idea is to try to collect while the memory is actively blowing up which this somewhat achieves

#

im not entirely sure but i think the major issue with this is that the game chokes on the gc calls and doesnt get to do much

#

but one thing is for sure this definitely works

#

i can handle a shit ton more retriggers now

#

in fact, the memory use is mostly negligible

hollow plinth
#

so is this some random luajit nuance or what

strange wave
#

It says right there globals are part of the root set and are preserved

hollow plinth
#

oh 😭

#

guess i read it wrong

#

well frequent garbage collection helps a shit ton in my uses so i suppose the issue is much different w vanilla and modded

#

id say that as far as i can tell the steamodded retrigger api is just kinda bad but i haven't even looked at it so 🥸

tall atlas
hollow plinth
#

it's a shame really idk i feel like that's what i would've prioritized considering the hard 2gb memory limit and the exponentially scaling nature of balatro mods

#

well considering im not the greatest my priority would be to make it work at all egg

tall atlas
#

I think the core issues are with Balatro’s vanilla scoring system

hollow plinth
#

if that's the case i wouldn't blame you tbh

#

because now that i think about it going to all that trouble just so that mods can go even more overboard for those giga numbers is kinda pointless

#

people are gonna try to reach whatever limit exists anyways so might as well let the limit stay low and save the hassle

tall atlas
#

Even another factor of 10 of improvements wouldn’t make a big difference imo in the experience of the mods

hollow plinth
#

true

tall atlas
#

Since it’s only with an extreme amount of triggers that this crashes
Mods like Cryptid just make that much easier to attain

#

My main changes when moving the API from Cryptid to Steamodded was removing all the jank from it

#

And adding a few more features

hollow plinth
#

i think it'd only be significant if you could make scoring not use memory or more realistically completely clean up after itself while it's running

#

but that's a task that requires rewriting the scoring system anyways

#

plus all the other things you have to worry about like mod compatibility and blah blah blah

ripe socket
#

is the file in the top of the thread the latest version? or is there any updates since that?

hollow plinth
#

oh i should post the one thats been doing better

#

one sec

ripe socket
#

i still get hard crashes when i try to limit test with godsmos

#

what were you using when you got your highest score?

glacial kettle
#

The reason mods cause issues is because a lot of them use the vanilla scoring system, which isn't designed for the mods use case

hollow plinth
#

iirc a godsmos and a mario multiplied to 2000 retriggers

#

the other stress test i did was with a jimbo and 10 million retriggers

ripe socket
#

how many cards in hand?

glacial kettle
#

I think the best way to tackle this issue, vanilla problems aside, is to create a more optimized and efficient API

hollow plinth
#

it was red deck white stake

ripe socket
#

yeah but for godsmos thats what matters

hollow plinth
#

play on red deck white stake and youll have as many as i did 🤷‍♂️

#

oh also

#

you should know

ripe socket
#

ah so you mean the default 8?

hollow plinth
#

you cant really interact with the game while its frozen else windows kills it

ripe socket
#

i know that

hollow plinth
#

then idk why ur having issues

ripe socket
#

thats what im trying to figure out

hollow plinth
#

whats ur modlist

ripe socket
hollow plinth
#

hm

ripe socket
#

like as soon as i go above the 140k one i just hard crashes

hollow plinth
#

when you look in task manager, does the memory just go straight up to 2.6 gb and then crash?

ripe socket
#

ok maybe it was a borderless issue or something cuz it aint crashing now

#

The hard crashing was also happening before this mod so it wasn't because of this mod btw

tall atlas
glacial kettle
clear oasis
#

Abandoned better_calc crying in the corner:

#

at this point it would probably have to be reworked from the ground up either way

clever rover
#

Meanwhile, my game starts to chug slightly at later antes even when my game isn't retriggering things hundreds of times

tall atlas
#

yes, because vanilla Balatro has a memory leak

ripe socket
#

btw unrelated to this mod but i found that if you press Alt + Esc you can minimize out of the game while its still doing the calculations, so you can actually still keep using your computer

clear oasis
#

doesn't it always do that in windowed?

ripe socket
#

wdym doesnt it always do that

clever rover
tall atlas
#

It’s worse when you have lots of consumables held

clever rover
#

Perkeo runs in shambles

clear oasis
ripe socket
#

yeah but in order to get it to go to the background without crashing it with alt tab i use this

clear oasis
#

I've had no issues with alt tabbing either...

glacial kettle
#

I mean I have a hunch that it's global related.

#

but most likely it's multiple problems, not just one big one.

#

something like this shows a pretty simple issue that can cause a memory leak.

hard anvil
#

what if we litterally just play the game, and have taskmanager open? cant we look at the spikes?

#

or sum

strange wave
tall atlas
#

Is there any way to dump the current memory when it gets pretty full to see what causes the most leaks?

#

This could be promising for finding memory leaks

strange wave
#

actually yestersday I was messing around and was wondering fi I could asomehow dump and load the memory for quick reloading after crahses. I found a library but didnt' dig much deeper

strange wave
#

baaltro has it's own kind of hooks for a lot of it's rendering stuff, so you could just hook it's function for setting those to degine the hooks

#

that sounds more useufl than the current profiler the game has

strange wave
#

also I don't think it's any more useful than the in game profile graph

tall atlas
# strange wave also I don't think it's any more useful than the in game profile graph

jprof requires you to annotate your code with "profiling zones", which form a hierarchical representation of the overall flow of your program and record time taken and memory consumption for each of these zones:

function foo()
    prof.push("do the thing")
    thething()
    prof.pop()
end

function bar()
    prof.push("foo it up in here")
    foo()
    prof.pop("foo it up in here")

    prof.push("something else")
    local baz = sum(thing, else)
    prof.pop("something else")
end
strange wave
#

yeah balatro aready kinda does this

tall atlas
#

I like the idea of splitting it up even further for memory usage

#

Because then you could see like, oh maybe Card:init is the function generating all the memory usage

strange wave
#

Oh I guess it is kindah andy for memory usage

tall atlas
#

Is there a way to like auto-generate the push/pop calls for every function in Balatro

#

Because then we just need to spawn like 100 cards and AFK to find the issue

strange wave
#

lovely regex patching

#

although the pop is harder

#

also it gets picky if something isn't being done in a frame

#

actuaslly

#

gimme a sec

#

we can

#

this is going to be so cursed

#

also defeats the purpose of this library

strange wave
#

ok idk it's not liking the data i made

#

I pushed a new commit that doesnt work but I don't know how to fix

winged crypt
#

@strange wave Decided to take a poke because why not, I don't have it fully working but it looks like MessagePack's injection needs to be above jprof's injection or you run into nil errors

winged crypt
#

actually, it does seem like it might be working, dunno how to use the files it outputs though

calm parrot
#

can i get a link for this mod?

#

seems too useful

strange wave
median summit
#

this mods incompatible with newest version of cryptid for some reason

olive pagoda
#

:c

#

yeah

#

just got a crash on startup from it

hollow plinth
#

(around 24 hours)

#

i should really make a better version of this anyways lol