Repository navigation
ArrayRef::new: encode the fill once; allocate array bodies fallibly - #9
Merged
Merged
Conversation
ArrayRef::new type-checked and encoded the same fill Val once per element after zero-filling the body, so allocating a large array to overwrite in place (submilli's $rawString, SUB-1668) did ~2 ops per element of waste. It now checks and encodes the fill once and replicates it; an all-zero fill is a single zeroed allocation. Array body builders (alloc, the i8 to_vec paths, i16_body) used infallible allocation that aborts the process even after the limiter admitted the bytes. All now go through try_reserve_exact; i16/i64 share one le_body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
submilli builds large strings by allocating an empty
$rawString(mutable i16 GC array) withArrayRef::new(.., &Val::I32(0), len)and filling it withwrite_i16(SUB-1668). That path:Valonce per element, on top of a zero-fill — ~64M wasted ops for a 32Mi-unit string;vec![0u8; byte_len], which aborts the process on allocation failure even after the limiter admitted the bytes.i16_body(flat_map().collect(), grows by doubling) and the i8to_vec()paths had the same issue.Change
ArrayRef::newchecks the fill once, reserves through the limiter, encodes it once into a stride-sized pattern, and replicates it. An all-zero pattern is just one zeroed allocation. (Null refs encode non-zero, so they take the copy path.)try_reserve_exact:alloc(new_fixed) useszeroed_body, i8 paths usecopied_body, i16/i64 share a genericle_body.body_len/check_elemhelpers. Minor behaviour change:new_fixednow rejects more thanu32::MAXelements.Tests (
tests/gc_host.rs)0x5_1234→0x1234), non-null anyref fill, and null fill.ArrayRef::newbefore any body exists.new_from_i8_slice/new_from_i16_slicewithu32::MAX + 1elements error before copying (64-bit only; inputs are lazily-mapped zero pages).cargo clippy --all-targets -- -D warningsandcargo test(with and without--features async) pass.🤖 Generated with Claude Code