memory usage and debug.sethook

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
rostok
Prole
Posts: 1
Joined: Wed Mar 22, 2023 7:50 pm
Contact:

memory usage and debug.sethook

Post by rostok »

Hello,
I am writing a game in PICOLOVE hybrid and been trying to reduce per-frame memory allocation to unburden garbage collector. My typical per frame gain is about 37kb, however every couple of seconds it suddenly grows to 100kb. This is not a big issue since GC can handle this without any impact on framerate. I've been trying to narrow it down and find out what exactly is causing these mem alloc bumps. To no avail.

However, I have encountered a strange phenomenon. Once I setup a totally bogus call hook to an empty function

Code: Select all

local function count_calls()
end
debug.sethook(count_calls, "c")
the memory allocation suddenly has no bumps and gets back to steady 37kb per frame.

I would like to know if anyone encountered this as well, what is the reason for this behavior and is it good to ship my game with such hook.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: memory usage and debug.sethook

Post by slime »

rostok wrote: Wed Oct 09, 2024 10:28 pm is it good to ship my game with such hook.
No, it'll interact very poorly with JIT compilation, and it'll make your code slower when it works.
rostok wrote: Wed Oct 09, 2024 10:28 pm I've been trying to narrow it down and find out what exactly is causing these mem alloc bumps. To no avail.
Something like https://github.com/pfirsich/jprof might help figure it out.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: memory usage and debug.sethook

Post by pgimeno »

In fact, it could be JIT-compiled code. Try jit.off() at the beginning of your main.lua instead of debug.sethook to find out. In any case, I'd say you don't need to worry because 100 kB is very reasonable. In more or less simple programs I've had garbage in the order of tens of MB, and they worked fine even in a Raspberry Pi 3.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests