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

lib: use arrow functions instead of bind #3622

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
@JungMinu
Copy link
Member

commented Nov 1, 2015

use arrow functions instead of bind(this) in order to improve
performance through optimizations.

@KenanY

This comment has been minimized.

Copy link
Contributor

commented Nov 1, 2015

I don't think you should touch anything in deps/npm/node_modules/ and tools/eslint/ since they contain third-party dependencies.

@JungMinu JungMinu closed this Nov 1, 2015

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

Yes, please be sure not to touch anything in deps/ or tools/eslint

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

@JungMinu instead of making a new PR you can just amend you changes (via git add and git commit --amend) and then force push it to this branch.

@JungMinu JungMinu reopened this Nov 1, 2015

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

@JungMinu actually; even more specific: please only do files in lib/ -- a change to the tests wouldn't be worth the change size I think.

@mscdex

This comment has been minimized.

Copy link
Contributor

commented Nov 1, 2015

Looks like the file permissions for the files in deps/ and tools/ are still being changed.

Also, have you done any benchmarking to show before and after these changes? Looking at the diff, I'm not sure that these changes actually affect any hot code paths.

@Trott

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

Except for the last sentence, the PR text appears to be copied from https://www.nczonline.net/blog/2013/09/10/understanding-ecmascript-6-arrow-functions/. If you want to use someone else's text verbatim, please remember to cite it.

@Trott

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

@jbergstroem

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

I'd be keen to see that benchmark as well before landing this.

@Trott

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

The win here, at least the way I see it, is in readability by getting rid of all the .bind(this) stuff. That's my opinion though. I wouldn't argue with someone else who thought that removing the explicit binding introduced too much magic. (I wouldn't agree, but I wouldn't argue either.)

As noted by @mscdex, none of this looks like it's in a hot path and so I very much doubt any of this will result in a measurable performance boost. Benchmark proving otherwise welcome, but it seems like the benefit here is a the readability/maintainability gain.

@mscdex

This comment has been minimized.

Copy link
Contributor

commented Nov 1, 2015

IMHO as far as readability goes, it's about the same, maybe worse (but that would be more of a general ES6 problem).

@jbergstroem

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

I guess where I was heading was that if this goes in with "faster" as the commit message it should be properly warranted. Style "fixes" is another category.

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

bind() is known to be slow, so if nothing else it makes institution faster. I'll look into the perf more, but also cc @trevnorris who originally suggested this kind of change

On Nov 1, 2015, at 6:39 PM, Johan Bergström notifications@github.com wrote:

I guess where I was heading was that if this goes in with "faster" as the commit message it should be properly warranted. Style "fixes" is another category.


Reply to this email directly or view it on GitHub.

@trevnorris

This comment has been minimized.

Copy link
Contributor

commented Nov 2, 2015

Minus the file permission changes, LGTM. As @mscdex mentioned, it's not an improvement in readability, but that's not what we're going after. In these specific locations there's nothing hot so won't notice a performance gain, but might as well make the change where it makes sense.

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 2, 2015

@JungMinu I'm not sure you caught every case of .bind() in the files under the lib folder. When I did a search I came up with 111 matches across 32 files. In addition, could you also check for any cases in src/node.js -- that's the only relevant file that is weirdly placed, I think.

Also how did you edit the files? I'm not sure what would have caused those mode changes.

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 2, 2015

Oh, maybe those mode changes were from previously changing those files..

@Fishrock123 Fishrock123 added lib / src and removed debugger tls labels Nov 2, 2015

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 2, 2015

ok, that search from my windows machine wasn't correct, but using Atom Editor I find 28 results across 7 files for lib/ for .bind(this. (It's possible searching for just .bind( will come up with some other results that could also be replaced, if you're feeling brave.)

Looks like there's nothing in src/node.js.

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Nov 3, 2015

Abandoning PRs and refiling them again is kind of annoying because it loses the discussion and the review history (of which there was quite a bit, it looks like.) Can I suggest you do a rebase, fix up the issues and force-push to your existing branch?

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Nov 3, 2015

If your implicit question is 'how?', check the documentation for git rebase -i a.k.a. interactive rebase.

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Nov 3, 2015

Presumably your editor did something to those files? When in doubt, use vim.

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 3, 2015

Hmm, A consideration we should make: If there is a obj.send = this.emit.bind(this, 'message') you'd probably call it like: obj.send(mymessage) which would apply as: this.emit.call(this, 'message', mymessage).

If it were possible () => this.emit('message', ...arguments) would work, however, arguments is not exposed in arrow functions.

Ideally we'd have (...args) => this.emit('message', ...args) but rest parameters (The first (...args)) doesn't yet exist..

We could write it as (a,b,c,d,e) => this.emit('message', a,b,c,d,f) but that is potentially not correct, and pretty messy.

@trevnorris Does that sound about right? I think we need to be careful for now.

Rest params come in v8 4.7, so we could just have this target master once that lands, even though it'l be 6 months until it ships then.

@cjihrig

This comment has been minimized.

Copy link
Contributor

commented Nov 3, 2015

Rest params come in v8 4.7, so we could just have this target master once that lands, even though it'l be 6 months until it ships then.

There is no rush on this change, right?

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Nov 3, 2015

There is no rush on this change, right?

@cjihrig Correct. (That being said, it would be nice to have subset in v5 if possible.)

@trevnorris

This comment has been minimized.

Copy link
Contributor

commented Nov 3, 2015

@Fishrock123 Currently rest parameters are even less optimized than bind(). Stay away from it. Far away.

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Jan 6, 2016

2016-01-06, Version 5.4.0 (Stable)
* http:
  - A new status code was added: 451 - "Unavailable For Legal Reasons" (Max Barinov) nodejs#4377
  - Idle sockets that have been kept alive now handle errors (José F. Romaniello) nodejs#4482
* This release also includes several minor performance improvements:
  - assert: deepEqual is now speedier when comparing TypedArrays (Claudio Rodriguez) nodejs#4330
  - lib: Use arrow functions instead of bind where possible (Minwoo Jung) nodejs#3622
  - node: Improved accessor perf of process.env (Trevor Norris) nodejs#3780
  - node: Improved performance of process.hrtime() (Trevor Norris) nodejs#3780, (Evan Lucas) nodejs#4484
  - node: Improved GetActiveHandles performance (Trevor Norris) nodejs#3780
  - util: Use faster iteration in util.format() (Jackson Tian) nodejs#3964

PR-URL: nodejs#4547

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Jan 11, 2016

2016-01-06, Version 5.4.0 (Stable)
* http:
  - A new status code was added: 451 - "Unavailable For Legal Reasons"
(Max Barinov) nodejs#4377
  - Idle sockets that have been kept alive now handle errors (José F.
Romaniello) nodejs#4482
* This release also includes several minor performance improvements:
  - assert: deepEqual is now speedier when comparing TypedArrays
(Claudio Rodriguez) nodejs#4330
  - lib: Use arrow functions instead of bind where possible (Minwoo
Jung) nodejs#3622
  - node: Improved accessor perf of process.env (Trevor Norris)
nodejs#3780
  - node: Improved performance of process.hrtime() (Trevor Norris)
nodejs#3780, (Evan Lucas)
nodejs#4484
  - node: Improved GetActiveHandles performance (Trevor Norris)
nodejs#3780
  - util: Use faster iteration in util.format() (Jackson Tian)
nodejs#3964

Refs: nodejs#4547
PR-URL: nodejs#4623
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

MylesBorins added a commit that referenced this pull request Jan 11, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: #3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

@MylesBorins MylesBorins referenced this pull request Jan 11, 2016

Merged

V5.4.1 propose #4626

MylesBorins added a commit that referenced this pull request Jan 11, 2016

2016-01-11, Version 5.4.1 (Stable)
Notable Changes:

* Minor performance improvements:
  - lib: Use arrow functions instead of bind where possible (Minwoo Jung) #3622.
    - (Mistakenly missing from v5.4.0)
  - module: move unnecessary work for early return (Andres Suarez) #3579
* Various doc fixes
* Various test improvements

PR-URL: #4626
@MylesBorins

This comment has been minimized.

Copy link
Member

commented Jan 13, 2016

Just putting a note here that this commit has still not landed in v5.4.x

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Jan 13, 2016

Some backstory on that:

  1. I screwed up my release tooling for v5.4.0 which missed this commit, and only this commit, since it was the first one in the list.
  2. @thealphanerd's Smoke-testing for v5.4.1 seemed to indicate this commit may have an error in it, but my testing afterwords seemed to indicate it was just tape's tests being flaky.

rvagg added a commit that referenced this pull request Jan 14, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: #3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

evanlucas added a commit that referenced this pull request Jan 20, 2016

2016-01-20, Version 5.5.0 (Stable)
Notable changes:

* events: make sure console functions exist (Dave) #4479
* fs: add autoClose option to fs.createWriteStream (Saquib) #3679
* http: improves expect header handling (Daniel Sellers) #4501
* node: allow preload modules with -i (Evan Lucas) #4696
* v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) #4463
* Minor performance improvements:
  - lib: Use arrow functions instead of bind where possible (Minwoo Jung) #3622
  - module: cache stat() results more aggressively (Ben Noordhuis) #4575
  - querystring: improve parse() performance (Brian White) #4675

PR-URL: #4742

evanlucas added a commit that referenced this pull request Jan 21, 2016

2016-01-20, Version 5.5.0 (Stable)
Notable changes:

* events: make sure console functions exist (Dave) #4479
* fs: add autoClose option to fs.createWriteStream (Saquib) #3679
* http: improves expect header handling (Daniel Sellers) #4501
* node: allow preload modules with -i (Evan Lucas) #4696
* v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) #4463
* Minor performance improvements:
  - lib: Use arrow functions instead of bind where possible (Minwoo Jung) #3622
  - module: cache stat() results more aggressively (Ben Noordhuis) #4575
  - querystring: improve parse() performance (Brian White) #4675

PR-URL: #4742
@balupton

This comment has been minimized.

Copy link

commented Jan 21, 2016

Regarding benchmarks, I'm not sure if the requests were for bind to arrow functions performance in general, or their performance when applied to node's codebase via this PR. For the former, for those interested, there is https://github.com/bevry/esnext-benchmarks which compares performance with several esnext features with the es2015 and other counterparts. Perhaps it will be useful for some readers. If it was the latter, can't help there.

MylesBorins added a commit that referenced this pull request Feb 17, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: #3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

MylesBorins added a commit that referenced this pull request Feb 18, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: #3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

@MylesBorins MylesBorins referenced this pull request Feb 18, 2016

Merged

V4.4.0 proposal #5301

MylesBorins added a commit that referenced this pull request Mar 2, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: #3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016

lib: use arrow functions instead of bind
use `arrow functions` instead of `bind(this)` in order to improve
performance through optimizations.

PR-URL: nodejs#3622
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016

2016-01-06, Version 5.4.0 (Stable)
* http:
  - A new status code was added: 451 - "Unavailable For Legal Reasons"
(Max Barinov) nodejs#4377
  - Idle sockets that have been kept alive now handle errors (José F.
Romaniello) nodejs#4482
* This release also includes several minor performance improvements:
  - assert: deepEqual is now speedier when comparing TypedArrays
(Claudio Rodriguez) nodejs#4330
  - lib: Use arrow functions instead of bind where possible (Minwoo
Jung) nodejs#3622
  - node: Improved accessor perf of process.env (Trevor Norris)
nodejs#3780
  - node: Improved performance of process.hrtime() (Trevor Norris)
nodejs#3780, (Evan Lucas)
nodejs#4484
  - node: Improved GetActiveHandles performance (Trevor Norris)
nodejs#3780
  - util: Use faster iteration in util.format() (Jackson Tian)
nodejs#3964

Refs: nodejs#4547
PR-URL: nodejs#4623
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016

2016-01-20, Version 5.5.0 (Stable)
Notable changes:

* events: make sure console functions exist (Dave) nodejs#4479
* fs: add autoClose option to fs.createWriteStream (Saquib) nodejs#3679
* http: improves expect header handling (Daniel Sellers) nodejs#4501
* node: allow preload modules with -i (Evan Lucas) nodejs#4696
* v8,src: expose statistics about heap spaces (`v8.getHeapSpaceStatistics()`) (Ben Ripkens) nodejs#4463
* Minor performance improvements:
  - lib: Use arrow functions instead of bind where possible (Minwoo Jung) nodejs#3622
  - module: cache stat() results more aggressively (Ben Noordhuis) nodejs#4575
  - querystring: improve parse() performance (Brian White) nodejs#4675

PR-URL: nodejs#4742

@zackify zackify referenced this pull request Apr 14, 2017

Merged

Update for react 15.5 #497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.