Skip to content
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

Chore: Use arrow functions where possible (lexical this). #7414

Closed
originalfoo opened this issue Jun 25, 2016 · 9 comments
Closed

Chore: Use arrow functions where possible (lexical this). #7414

originalfoo opened this issue Jun 25, 2016 · 9 comments
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.

Comments

@originalfoo
Copy link
Contributor

originalfoo commented Jun 25, 2016

  • Version: 6.2.1
  • Platform:
  • Subsystem: various

Following on from #7295, I've spotted similar pattern in many other files:

var self = this;
something(someFunc(...) {
  self.whatever();
});

In most scenarios, this pattern can be replaced with an arrow function, allowing removal of 'self' var:

something((...) => {
  this.whatever();
});

I'd like to use this issue ticket as a hub for several commits/PRs relating to this (one changed file per PR, although there may be several commits in the PR - one for each arrow function implemented in the file).

originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
This commit merits extra scrutiny.

Refs nodejs#7414
@addaleax
Copy link
Member

although there may be several commits in the PR - one for each arrow function implemented in the file

It’s up to the one who creates the PR how they do it, but the commits will very likely be squashed together anyway.

originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
Extra scrutiny required for this change

Refs nodejs#7414
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
originalfoo added a commit to originalfoo/node that referenced this issue Jun 25, 2016
@originalfoo
Copy link
Contributor Author

@addaleax it's more so I can interactive rebase or cherry-pick should a specific commit need removing etc; just sort of a habit I got in to.

@addaleax
Copy link
Member

@aubergine10 As said, it’s up to you. :)

Tbqh, I’d like to hear or work out some kind of rule of thumb of which types of style-only changes are generally considered worthwhile. These kind of changes tend to generate a lot of noise, and while I see that something like #7378 can improve readability noticeably, I’m not sure that’s always the case.

@originalfoo
Copy link
Contributor Author

@addaleax Ultimately it will probably depend on whether there are any improvements in terms of performance, gc, RAM consumption, etc. I'm not skilled enough to determine whether there are any tangible benefits to replacing the var self... pattern with arrow functions. I imagine the V8 optimising compiler will already seek to avoid creating unnecessary arguments objects, etc?

@addaleax
Copy link
Member

I wouldn’t expect any significant performance difference, no.

@originalfoo
Copy link
Contributor Author

originalfoo commented Jun 25, 2016

Based on the discussion yesterday I did some googling regarding performance of arrow functions and other ES6 features and found this: http://kpdecker.github.io/six-speed/

If those results are correct, it looks like ES6 features, in general, are currently offering very little benefit over their ES5 counterparts and in many cases result in notably worse performance.

I noticed that the Node.js test scripts include some performance tests but I'm not sure how to extract that data and compare to data from the unmodified scripts... Would be interesting to see what the performance impact is of the current two batches of edits. Without a clear improvement in performance, I don't think there's any benefit to using arrow functions over the ES5 approach.

Another interesting read on arrow functions: https://blog.getify.com/arrow-this/

@Fishrock123
Copy link
Contributor

Arrow functions are great for replacing Function#bind() -- I think we've already done most or all of that though.

@lance
Copy link
Member

lance commented Jul 8, 2016

Heh - so, after submitting a PR for repl.js on this, I decide to read the comments. I'll leave the PR open for now anyway...

Curious that certain arrow operations are slower than ES5 (semi-)equivalents. Without any real understanding of how V8 implements these language features it seems arrow functions should typically perform faster because the runtime doesn't need to allocate a new this or arguments for the function. But that's just napkin scratching.

jasnell pushed a commit that referenced this issue Aug 18, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this issue Aug 24, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this issue Sep 30, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this issue Sep 30, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this issue Oct 10, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
rvagg pushed a commit that referenced this issue Oct 18, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this issue Oct 26, 2016
Refs: #7414
PR-URL: #7415
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@mscdex mscdex added the lib / src Issues and PRs related to general changes in the lib or src directory. label Nov 23, 2016
@jasnell
Copy link
Member

jasnell commented May 30, 2017

Closing. This has been happening incrementally

@jasnell jasnell closed this as completed May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

No branches or pull requests

6 participants