Yet another attempt at typed JS data

Jordan Harband ljharb at gmail.com
Sun Feb 9 21:00:27 UTC 2020


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200209/a5a9dc69/attachment.html>


More information about the es-discuss mailing list