Answer: Recommended starting values
When the generational collector is enabled via collectgarbage('generational'), a good initial configuration is:
pause = 100 (percent of current memory before a GC cycle is triggered)
step multiplier = 200 (work done per incremental step)
These values are a baseline; adjust them based on measured pause latency or allocation rate.
Likely explanation vs. confirmed facts
Likely explanation (based on the generational design): The pause parameter primarily controls how often the young generation is collected. A lower pause causes more frequent minor collections, which are typically short, thus reducing the worst‑case pause latency but increasing overhead. The step multiplier influences the amount of work done in each incremental step of both minor and major collections; raising it shortens total GC time but can lengthen individual step pauses.
Confirmed facts from Lua 5.4 source: The generational mode splits objects into young and old generations. Minor collections scan only the young generation; major collections occur when the old generation grows enough to trigger a full cycle. The pause and step multiplier parameters are still interpreted as percentages and multipliers exactly as in the incremental collector, but their impact on pause latency is mediated through the frequency and cost of minor versus major cycles.
Steps to tune for your workload
- Enable generational mode:
collectgarbage('generational')
- Set the baseline values (
pause=100, step=200) via the C API or lua_gc.
- Run a representative allocation loop (e.g., creating many tables) and measure the time between GC pauses using a debug hook or
lua_gc(L, LUA_GCSTEP, 0) with timestamps.
- If observed minor‑GC pauses are too long, decrease
pause (e.g., to 50) to trigger more frequent, shorter minor collections.
- If overall throughput suffers (mutator spends too much time in GC), increase
step multiplier (e.g., to 300) to do more work per step, but watch for longer step pauses.
- Iterate until pause latency and overhead meet your targets.
Missing diagnostic detail that could change the recommendation
To refine the suggestion, we need to know the observed allocation rate (bytes per second) or the measured average minor‑GC pause latency for your application. If the allocation rate is very high, a lower pause may be necessary; if minor pauses are already negligible, you could raise pause to reduce overhead.