You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tables are never freed: a long-lived state grows ~1.6 MB per 1,000-row render #429
ROADMAP lists GC and weak tables as a deliberate non-goal for 1.0. This issue is about what that costs a host that keeps one state alive and does real work in it, plus a narrow proposal that doesn't need the full gc.lua semantics.
Numbers
A render that builds 1,000 small row tables, joins them into a string and returns the string. No table survives the call:
(main @ 3f2aead, Apple M4, OTP 29. collectgarbage("count") returns 0.0.)
Memory grows linearly with work done, not with live data. Time grows faster than linearly, presumably because the BEAM copies an ever-larger state. In our host (an agent's computer that runs Lua under a 64 MB process heap), about 20 server-rendered HTML pages in one run hit the cap. Each page renders in about 17 ms on its own.
Proposal: collect at safe points
The hard part of collecting during a run is that live registers are Erlang locals in the dispatcher. There is one point where no Lua frame is live: between host calls, after Lua.eval! or Lua.call_function has returned.
Lua.gc(lua) (or an opt-in :gc option applied on return) marks from the roots: _G, package.loaded, the metatables for each type, the upvalue cells of reachable closures, and the tables reachable from them.
Values the host still holds ({:tref, id} handed out by Lua.get!, decoded returns, and so on) would need pinning, or would be documented as invalid after gc.
Then sweep tables and upvalue_cells.
This frees a long-lived state's garbage without touching the hot path. A later step could run the same mark during a run at collectgarbage() calls, with roots taken from the frames.
We'd be glad to send a PR for the between-calls version if the shape is acceptable. Related: #425.
Reacted by sclee-aether, m0rt3nlund and Yannis Weishaupt
Activity