I remember doing similar benchmarks for `String.fromCharCode` with a wrap
of the native function that was splitting invokes in chunks of 2K chars MAX
per operation ... but I think the arguments limits, which is the same you
have in `push` is a JS issue as a whole, not something array specific.

As side note, `append(...items) { return this.push(...[...items]), this; }`
would be equivalent, but you could also write this without needing to add
yet another method to the Array: `(array.push(...items), array)` looks easy
to my eyes, nothing new to learn.

My 2 cents

On Thu, May 24, 2018 at 9:33 AM, T.J. Crowder <
tj.crow...@farsightsoftware.com> wrote:

> On Wed, May 23, 2018 at 11:06 PM, Isiah Meadows <isiahmead...@gmail.com>
> wrote:
> >
> > Since `Array.prototype.push` is variadic, I don't see how this would be
> any improvement on the status quo (which isn't that bad to begin with).
>
> On Wed, May 23, 2018 at 9:14 PM, Tab Atkins Jr. <jackalm...@gmail.com>
> wrote:
> > On Wed, May 23, 2018 at 1:05 PM, Jordan Harband <ljh...@gmail.com>
> wrote:
> >> `array.push(...sources)`, not sure why we'd need "append".
> >
> > From the original email (a bit buried and hard to find due to broken
> > threading, admittedly):
> >
> >> Has anyone ever suggested Array.prototype.append as an
> Array.prototype.push which returns the array itself?
> >
> > The point is x.append(y) returning x, whereas x.push(y) returns y.
>
> With large arrays you can also run into a platform's stack size limit
> with a large number of arguments. I got curious, and unless [my
> test][1] is significantly flawed, that limit is definitely a factor.
> The test uses `dest.push.apply(dest, source)` and works in chunks of
> 10k entries, reporting the point at which it got a stack error:
>
> * Chrome v66: Between 120k and 130k entries
> * Firefox v60: 500k - 510k
> * Edge v41: 650k - 660k
> * IE11: 250k - 260k
> * IE8¹: 5.25M (!) - 5.26M
>
> Using `dest.push(...source)` [instead][2] gave the same numbers as
> above on Chrome, Firefox, and Edge.
>
> So two reasons: Returning the array, and not pushing (no pun) the
> limit. ~125k entries isn't all that many.
>
> -- T.J. Crowder
>
> ¹ *Hey, some people still have to support it (e.g., via transpilation)
> -- old embedded IE-based apps in large institutions, etc. I'm just
> glad not to be one of them.*
>
> [1]: http://output.jsbin.com/jeperatefi
> [2]: http://output.jsbin.com/sucokosipu
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to