Yet another attempt at typed JS data

Isiah Meadows contact at isiahmeadows.com
Tue Feb 11 16:47:47 UTC 2020


Edit: never mind. In either case, it's an engine problem, not a spec
problem.

I wouldn't mind a couple things that could desugar to that making it in
(like `Array.range`), but those all have something special the engine can
do to fill it in less than half the time provided appropriate ISA support.

On Tue, Feb 11, 2020 at 08:44 Isiah Meadows <contact at isiahmeadows.com>
wrote:

> You have proof of this? That it doesn't produce a dense array in engines?
>
> On Mon, Feb 10, 2020 at 01:09 Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
>> Unfortunately, `Array.from({ length: 4 }, () => whatever)` produces a
>> holey array, so that the `.repeat(...)` idea, if capable of packing
>> elements in a better way, wouldn't be so terrible, as simplification.
>>
>> Although, the intent of this proposal was to also grant "shapes" or
>> kindness of each entry, same way typed Arrays do, but maybe that would
>> require some better primitive, as in `const Shape =
>> Object.defineShape(...)` and `Object.createShape(Shape)` or similar.
>>
>> On Sun, Feb 9, 2020 at 10:01 PM Jordan Harband <ljharb at gmail.com> wrote:
>>
>>> That already exists - `Array.from({ length: 4 }, () => whatever)` - I
>>> assume that the hope is to have an array where it is *impossible* for it to
>>> have the wrong "kind" of data, and a userland factory function wouldn't
>>> provide that.
>>>
>>> On Sun, Feb 9, 2020 at 10:39 AM kai zhu <kaizhu256 at gmail.com> wrote:
>>>
>>>> > It's a bit of a mess to create an Array that is not holed and gets
>>>> best optimizations [1], and this proposal would like to address that exact
>>>> case.
>>>>
>>>> could the performance issue be resolved more easily with a simple
>>>> static-function `Array.repeat(<length>, <repeater>)`?
>>>>
>>>> ```js
>>>> let structuredList;
>>>> structuredList = Array.repeat(4, function (ii) {
>>>>     return {
>>>>         index: 2 * ii + 1,
>>>>         tags: []
>>>> });
>>>> /*
>>>> structuredList = [
>>>>     { index: 1, tags: [] },
>>>>     { index: 3, tags: [] },
>>>>     { index: 5, tags: [] },
>>>>     { index: 7, tags: [] }
>>>> ];
>>>>  */
>>>> ```
>>>>
>>>> the only time i can practically enforce the shape of a
>>>> "StructuredArray" is during element-insertion,
>>>> and a userland insertion/creation function would be just as effective
>>>> as a StructuredArray constructor.
>>>>
>>>> enforcing shapes during element deletions and updates are going to be
>>>> hard
>>>> and likely just as confusing with StructuredArray as they are with
>>>> regular Array.
>>>>
>>>> also note that most javascript arrays need to be easily JSON-serialized
>>>> for message-passing
>>>> over-the-wire (commonly http) to external systems.
>>>>
>>>> -kai
>>>>
>>>> On Sat, Feb 8, 2020 at 3:46 AM Andrea Giammarchi <
>>>> andrea.giammarchi at gmail.com> wrote:
>>>>
>>>>> > having to retroactively add checks like...
>>>>>
>>>>> we already have typed arrays in JS so I don't think this would be any
>>>>> different
>>>>>
>>>>> > I _think_ that moderns virtual machines already did these
>>>>> optimisations despite there isn't a TypedArray like that.
>>>>>
>>>>> It's a bit of a mess to create an Array that is not holed and gets
>>>>> best optimizations [1], and this proposal would like to address that exact
>>>>> case.
>>>>>
>>>>> [1] https://v8.dev/blog/elements-kinds
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> es-discuss mailing list
>>>>> es-discuss at mozilla.org
>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> --
> -----
>
> Isiah Meadows
> contact at isiahmeadows.com
> www.isiahmeadows.com
>
-- 
-----

Isiah Meadows
contact at isiahmeadows.com
www.isiahmeadows.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200211/567576df/attachment.html>


More information about the es-discuss mailing list