[builtins] Add Array.p.join fastpath for single element array.
This is resurrecting an optimization from the pre-torque version. Avoid allocating another sequential string for the result when there's only one element, just return the ToString-ed element. This not only saves time writing to this destination string, but also reduce GC pressure. The System Health Memory Benchmark (load:media:google_images) exposed this missing optimization with a 15% regression in memory usage. Very large external strings were being copied into V8's heap as sequential string. Bug: chromium:896612 Change-Id: Ieb61906f64100cdc15bf96f3ebcccb1207f75356 Reviewed-on: https://chromium-review.googlesource.com/c/1316620 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Peter Wong <peter.wm.wong@gmail.com> Cr-Commit-Position: refs/heads/master@{#57241}
This commit is contained in:
parent
87e1b85d9f
commit
986aa36b1f
@ -222,6 +222,27 @@ module array {
|
||||
assert(IsValidPositiveSmi(buffer.totalStringLength));
|
||||
if (buffer.totalStringLength == 0) return kEmptyString;
|
||||
|
||||
// Fast path when there's only one buffer element.
|
||||
if (buffer.index == 1) {
|
||||
const fixedArray: FixedArray = buffer.fixedArray;
|
||||
typeswitch (fixedArray[0]) {
|
||||
// When the element is a string, just return it and completely avoid
|
||||
// allocating another string.
|
||||
case (str: String): {
|
||||
return str;
|
||||
}
|
||||
|
||||
// When the element is a smi, use StringRepeat to quickly build a memory
|
||||
// efficient separator repeated string.
|
||||
case (nofSeparators: Number): {
|
||||
return StringRepeat(context, sep, nofSeparators);
|
||||
}
|
||||
case (obj: Object): {
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const length: uint32 = Convert<uint32>(Unsigned(buffer.totalStringLength));
|
||||
const r: String = buffer.isOneByte ? AllocateSeqOneByteString(length) :
|
||||
AllocateSeqTwoByteString(length);
|
||||
|
@ -4,4 +4,4 @@ Running test: testMaxConsoleMessagesCount
|
||||
Messages reported: 1000
|
||||
|
||||
Running test: testMaxConsoleMessagesV8Size
|
||||
Messages reported: 3
|
||||
Messages reported: 5
|
||||
|
Loading…
Reference in New Issue
Block a user