lua-users home
lua-l archive

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



On 5/5/23 13:38, Luiz Henrique de Figueiredo wrote:
My conclusion is that all memory management should be left to Lua. You should trust its garage collection.

That's definitely my approach when writing a "main" a program, there's just no way Lua's gc will be more expensive than the effort needed to squeeze performance through micromanaging, most of the time.

But I've learned to be a bit more careful with heavily used core libraries. My stuff runs for a while and consumes a bunch of RAM (simulations, graph traversals, and so on). Not hitting the swap may be the difference between 10 minutes of runtime and a few hours.

Rewriting an internal data structure to allocate smarter, like changing an {{x1,y1}, {x2,y2},...} to {x1,x2,...},{y1,y2,...}, can make a huge difference in RAM usage and gc costs when you have millions of entries and your operations allocate in a tight loop.


Jorge