The latter increases polymorphism. As a general principle, V8 tries to
avoid flip-flopping of types/maps/etc; instead it prefers to settle into a
stable state as quickly as possible. That why so far, the rule has been
"once an array is holey, it'll stay holey forever".

The former avoids the flip-flopping but is more difficult to accomplish. If
done partially (e.g. only in optimizing compilers with code dependencies on
pristine Array.prototype), it also increases polymorphism, as well as risk
of deopts.

So the cost of increased polymorphism (and perhaps deopts) has to be
weighed against the (fairly minor) benefit of a few avoided hole checks.
I'd say some very careful benchmarking is in order to demonstrate that the
wins justify the additional complexity.


On Wed, Feb 12, 2025 at 11:22 AM Marja Hölttä <[email protected]> wrote:

> Hi,
>
> I was wondering whether breaking the invariant "elements transitions
> always go from specific to generic" will break something. I don't know. But
> given that Vyacheslav proposed doing this, and nobody came up with
> objections detailing what will break, maybe it won't break anything?
>
> Is the goal to just optimize "Array(n).fill(something)" (that exact
> syntactic pattern) or more generally, make Array.prototype.fill transition
> to a more specific ElementsKind if certain conditions are met?
>
>
> On Mon, Feb 10, 2025 at 6:53 PM Benjamin Kietzman <[email protected]>
> wrote:
>
>> Currently, calling Array.fill will produce an array with HOLEY elements.
>>
>> > %DebugPrint(Array(1).fill(0))
>> DebugPrint: 0000015DF1C8CF29: [JSArray]
>>  - map: 0x00280f5cf721 <Map[32](HOLEY_SMI_ELEMENTS)> [FastProperties]
>>  - prototype: 0x02f93035a851 <JSArray[0]>
>>  - elements: 0x015df1c8cf49 <FixedArray[1]> [HOLEY_SMI_ELEMENTS]
>>  - length: 1
>>
>> This seems like a missed opportunity for optimization since the new array
>> could be upgraded to PACKED_SMI_ELEMENTS. There's a very old issue about
>> this https://issues.chromium.org/issues/42210138 which hasn't collected
>> any objections.
>>
>> I'd be a first time contributor to V8 but I'd be happy to try patching
>> this. All advice would be welcome!
>>
>> Ben Kietzman
>>
>> --
>>
>>

-- 
-- 
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 visit 
https://groups.google.com/d/msgid/v8-dev/CAKSzg3Rk7jWM0PHfxjsFT6H6tkQ2G1jbezGTYBc3z-cMFK9XwQ%40mail.gmail.com.

Reply via email to