Repository navigation
Conversation
…sight
A table's array part was a []Value, which the GC scans whole on every cycle.
sieve's 50000-slot arrays of booleans cost it a scan about once per table.
A slot that holds nil, a boolean or a number has a pointer only to a tag, a
global. While a table's array part holds nothing else it is now allocated as
scalarSlots, a Value's layout with a uintptr where the pointer was, which the
GC does not scan, and read as []Value as before. Table.ptrArr records that the
array may hold pointers; arrToPtrs moves the array to memory the GC scans
before the first one is stored. Stores go through arrSet, or check the flag.
A resize picks the kind from what goes into the new array.
In the loops, SETTABLE needs the check only when the slot's p changes, or for
an append: a value with the slot's own p cannot be the array's first pointer.
NEWTABLE's C operand, unused until now, is set when every positional item of
the constructor is a number, boolean or nil literal, or an arithmetic,
comparison or unary expression. It is a hint: without it, {left, right} would
allocate its array twice.
The tests store fresh tables through each path that writes an array part,
collect, and check by weak pointers that the GC sees them; a randomized run
checks the same rules and the contents against a model.
sieve takes 8 to 26 percent less time on the fast loop. The fast loop's
instruction counts are within 1 percent of before, except parse at 1.9 percent
fewer; the checked loop's rise by up to 1.9 percent, and fannkuch is 3 to 9
percent slower there.
folbricht
force-pushed
the
scalar-arrays
branch
from
November 24, 2026 09:44
839d6fc to
318aef5
Compare
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.
Option A from the Value redesign. It is now based on main: it does not need #57.
What it does
While a table's array part holds only nil, booleans and numbers, it is allocated as
scalarSlots: aValue's layout with auintptrwhere the pointer was. The GC doesn't scan it, and the code reads it as[]Valueas before.Table.ptrArrrecords that an array may hold pointers. Before the first one is stored,arrToPtrsmoves the array to memory the GC scans.SETTABLEneeds the check only when the slot's pointer word changes, or for an append. A value with the slot's own pointer word can't be the array's first pointer.NEWTABLE's unused C operand carries a compiler hint, set when every positional item is a number, boolean or nil literal, or an arithmetic, comparison or unary expression. Without it,{left, right}allocates its array twice.NewTablekeeps allocating arrays that can hold pointers.Safety
A pointer in an unscanned array would let the GC free an object that the table still refers to. The tests store fresh tables through the paths that write array parts, collect, and check through weak pointers that the GC sees them. A randomized run checks the same rules, and the contents against a model.
I broke 18 guards and allocations one at a time. The tests catch 17. The other, the checked store in
table.pack, is redundant, because the array's kind is chosen from the same values.An earlier version of this description said the test covered every write path. It did not: of the 14 mutants I first tried, 8 went unnoticed, one of them the redundant store in
table.pack. A later version gave that count as 7.Also passing: the full suite,
-race,lua_stackstress, arm64 vet, asmgate, and the corpus, suite and table tests underGOGC=1.Results against main
sieve, time in interleaved runs, fastest and median. The fast loop's range is over two sets of runs; the other rows are one set of 9:
Costs:
The gain is limited to scripts with large arrays of numbers or booleans. Most of the GC-marking gap comes from write barriers on the register stack, which this doesn't touch.