Home > Mobile >  HARFANG framerate drop Lua vs Python
HARFANG framerate drop Lua vs Python

Time:11-14

I'm testing the Lua (5.3) Harfang to benchmark the performances vs another framework. The use case is a large amount of sprites. I noticed some annoying framerate drops, but I cannot find any pattern that would explain it. Sometimes it will drop (pause) 2 or 3 times per second, sometimes the framerate will remain stable for a short period, then it drops again.

I experimented the same routine, in Python, and in Python it's PERFECTLY OK...

Any help ? (the amount of sprites is approx. 3000 objects, stored in a Lua table)

CodePudding user response:

As @LMD suggested, this is a typical issue with the garbage collector of Lua :) A radical workaround could be to invoke the GC explicitely from within the main rendering loop :

while not hg.ReadKeyboard():Key(hg.K_Escape) do
    hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.Color.Black, 1, 0)
    hg.SetViewRect(0, 0, 0, width, height)

    dt = hg.TickClock()
    dt_f = hg.time_to_sec_f(dt)

    -- do your rendering stuff here with lots of objects

    hg.Frame()
    hg.UpdateWindow(window)

    collectgarbage() -- prevent GC-induced frame drops
end

Try this, the framerate drops should be gone. It doesn't happen with Python, indeed.

Edit

Since the release of Lua5.4, this explicit call to the GC should not be required anymore. Lua 5.4 release notes reads the following :

new generational mode for garbage collection 

The generational mode shows better performances. When tested in Harfang, the framerate drop doesn't occur anynmore (at least on the most obvious use cases).

  • Related