New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of splat func arguments #857

Closed
summivox opened this Issue Feb 20, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@summivox
Contributor

summivox commented Feb 20, 2016

According to Petka, calling slice$ on arguments kills v8 optimization. He suggested to do a naive indexed for loop on arguments instead.

Currently:

f = (a, ...b, c) ->

compiles to:

f = function(a){
  var i$, b, c;
  b = 1 < (i$ = arguments.length - 1) ? slice$.call(arguments, 1, i$) : (i$ = 1, []), c = arguments[i$];
};

summivox added a commit to summivox/LiveScript that referenced this issue Feb 21, 2016

summivox added a commit to summivox/LiveScript that referenced this issue Feb 21, 2016

@summivox

This comment has been minimized.

Contributor

summivox commented Feb 21, 2016

I did a patch (summivox/LiveScript@e6591cf) but it currently relies on #859 being merged. It can be done without #859 but I'm too lazy 😉

This patch itself does not change any semantics -- the only change is inlining slicing of arguments. Therefore I did not add/change any tests.

It works by inlining slice$ as a list comprehension. Above example compiles to:

f = function(a){
  var i$, b, res$, j$, c;
  res$ = [];
  for (j$ = 1 < (i$ = arguments.length - 1) ? 1 : (i$ = 1); j$ < i$; ++j$) {
    res$.push(arguments[j$]);
  }
  b = res$; c = arguments[i$];
};

According to http://jsperf.com/arguments-to-array/43

  • prealloc-assign is the fastest on Chrome
  • ES6 varargs (native splat) is the fastest on Firefox, followed by empty-push then prealloc-assign
  • slice$.call(arguments) is universally slow

However, as long as we get rid of deoptimization, the cost of a single slice should be negligible. Prealloc-assign is much harder to implement than list comprehension/empty-push.

@isiahmeadows

This comment has been minimized.

Contributor

isiahmeadows commented Mar 21, 2016

Ping @gkz (Babel and TypeScript do this by default, and CoffeeScript has been annoying people with the slow progress)

@summivox

This comment has been minimized.

Contributor

summivox commented Mar 21, 2016

@isiahmeadows : currently @vendethiel is in charge (and yes he did comment on that issue too).

BTW: #859 has been merged, so I can actually make a pull request now.

@isiahmeadows

This comment has been minimized.

Contributor

isiahmeadows commented Mar 22, 2016

@summivox Okay. I didn't know this.

(I don't keep up with this as much as I used to. LS 2.0 does seem pretty interesting, though.)

@gkz gkz closed this in e289016 May 15, 2016

This was referenced Jan 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment