Perl_av_extend_guts: initialize elements via Zero() rather than while loop(s) #18072
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.
This PR has two commits, a tabs-to-spaces commit, followed by a refactoring commit. The latter:
No change in behaviour is intended, this PR is solely intended to improve performance when large arrays are created or resized.
However, the performance difference will be dependent upon the underlying memset/memzero implementation. It would be great if this PR could get some testing on different platforms in order to see if any show worse performance than before.
Local perf testing
On a Core i5 x86-64 Linux VM:
my @ary; for (1 .. 1_000_000) { @ary = (1); undef @ary; }
my @ary = (1,2,3); for (1 .. 1_000_000) { shift @ary; shift @ary; push @ary, (4,5); }
my @ary; for (1 .. 1_000_000) { @ary = (1); $ary[1024] = 1; undef @ary; }
blead:
patched:
Questions/scope for additional commit(s)?
Can *maxp can ever be < -1? If it can't, the
(UNLIKELY(key < -1))
test could be made an else branch off the if(key > *maxp) {
test.When a shifted array
(*allocp != *arrayp)
has to be grown:(key > *maxp - 10)
and not just a repeat of(key > *maxp)
? Seems like this will cause small arrays to be always be grown, even if there's no actual need.newmax = key + *maxp
, but for an unshifted array it'snewmax = *maxp / 5
?If shifted arrays were treated the same as unshifted arrays in those regards, it would simplify the function and could reduce unnecessary array growth.