Skip to content

Better handling of splat func arguments #857

Description

@summivox

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$];
};

Activity

  1. added 2 commits that reference this issue on Feb 21, 2016
    a056eb9
    e6591cf
  2. summivox commented on Feb 21, 2016

    @summivox
    ContributorAuthor

    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.

  3. dead-claudia commented on Mar 21, 2016

    @dead-claudia
    Contributor

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

  4. summivox commented on Mar 21, 2016

    @summivox
    ContributorAuthor

    @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.

  5. added a commit that references this issue on Mar 21, 2016
    93ec60f
  6. dead-claudia commented on Mar 22, 2016

    @dead-claudia
    Contributor

    @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.)

  7. added a commit that references this issue on Mar 22, 2016
    e289016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions