lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 2020/12/13 10:39, nerditation wrote:
> Just a wild guess, when you create a dummy table, this triggers a gc cycle, while the empty
> callback doesn't allocate anything thus gc didn't have a chance to run.
> try the following to verify whether this is the case, this code force a full gc:
> ```
> void test(lua_State *luaState, unsigned testIterationsCount, size_t userDataSize) {
>     for (unsigned i = 0; i < testIterationsCount; ++i) {
>         lua_getglobal(luaState, "callback");
>         pushObject(luaState, userDataSize);
>         lua_call(luaState, 1, 0);
>     }
>     lua_gc(LUA_GCCOLLECT);
> }
> ```
> or alternatively, you may run a single gc step in every iteration to amortize the gc overhead.

Thanks for the attention nerditation!

Indeed, I believe the dummy table triggers a gc cycle.

I tried your ideas. The full gc will collect part of the dead objects as
expected. The gc step (stepsize = userDataSize) on each iteration will keep
memory usage low, although with a performance penalty far greater (about 2x the
time) than using the dummy table without explicitly calling the garbage collector.

I have little knowledge about garbage collectors. Does anyone know why the
allocated function argument objects do not (or barely) affect the gc? Is this
such and edge case that it is not worth the trouble to be dealt with? That is
not a flaw in my opinion, I am asking just out of curiosity =].

André Henriques