I guess 0 is by far the most common case.

A patch is easy enough:
https://chromium-review.googlesource.com/c/v8/v8/+/3687700

Locally, I'm seeing 1.5x - 2x improvement, far from 10x but clearly
measurable for large arrays.


On Fri, Jun 3, 2022 at 1:10 PM Leszek Swirski <[email protected]> wrote:

> I guess we could do it for anything where all two/four bytes of the fill
> value are identical? Probably (aside from 0) an unusual case like you say,
> but the complexity of checking it should be low enough.
>
> On Fri, Jun 3, 2022 at 11:56 AM Marja Hölttä <[email protected]> wrote:
>
>> Interesting, thanks for making us / me aware of this.
>>
>> It sounds like a generally reasonable optimization; at least in the
>> fill(0) case. Not sure how common fill(-1) is but if it doesn't increase
>> the code complexity too much, why not.
>>
>>
>> On Fri, Jun 3, 2022 at 11:34 AM Ashton Six <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I noticed `new Int8Array(int32.buffer).fill(-1)` is equivalent to
>>> `int32.fill(-1)` but 10x faster, since [Uint, Int]8.fill() uses memset
>>> whereas every other implementation of TypedArray.fill() uses a for loop (
>>> https://github.com/llvm/llvm-project/blob/8bb1dbbf7544eaac3afab8d1f91b71f383dab903/libcxx/include/algorithm#L1987-L2005).
>>> Benchmark: https://jsbench.me/1zl3y8q6q7/1.
>>>
>>> Is it worth making this optimisation part of v8 for TypedArray.fill(0),
>>> Int16Array.fill(-1) and Int32Array.fill(-1)?
>>>
>>> Regards,
>>> Ashton
>>>
>>> --
>>> --
>>
>>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAKSzg3QcbvNr6twa1HGqccA2_qd%3Dp8daRCn8OQqTLGrA7kuc3A%40mail.gmail.com.

Reply via email to