Conversation
tommyscholly
requested changes
Sep 29, 2026
Contributor
There was a problem hiding this comment.
Please reset gcstats.endtimestamp and gcstats.endtotalsizebytes at the end of luaC_fullgc() as well.
Otherwise, lua_allocationrate() will continue to report 0 after a full collection until the heap exceeds its previous size, even when allocations occur.
Additionally, I would like to see this test allocate after the full GC and check that lua_allocationrate() becomes positive.
Additionally additionally we should probably flag these changes I'm requesting as well.
Contributor
Author
|
Thanks, good catch! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The GC measures heap growth since the end of the last incremental cycle as
atomicstarttotalsizebytes - endtotalsizebytes(andtotalbytes - endtotalsizebytesinluaC_allocationrate). Both operands aresize_t, so when the heap is smaller than it was at the end of the last cycle, the subtraction wraps around. This can happen in two ways:lua_gc(L, LUA_GCCOLLECT, 0)) frees memory but doesn't update the incremental cycle statisticslua_allocationrate()after a full collection-9223372036854775808018446744073709253349bytes0bytes1.08e21bytes/s0bytes/sThe double to int64 conversions of these values are undefined behavior (reported by UBSan in
luaC_allocationrateandgetheaptrigger).lua_allocationratewas added in 0.731 to pace the GC externally, so an embedder that runs a full collection gets a garbage rate right after it.This change treats a heap that shrank as zero growth. When the heap grew, the results are unchanged. The fix is behind
DFFlag::LuauGcHeapShrinkFixand the flag-off paths keep the original expressions.Resetting the cycle statistics in
luaC_fullgcwould only cover the first case, so the growth is clamped instead.Added
ApiAllocationRateAfterFullGC, which fails without the fix (lua_allocationratereturns-9223372036854775808).