-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: replace self/bind usage with arrow func #3816
Conversation
LGTM if the CI is happy |
I'm curious as to any performance impact this may have. I know that Does anyone have actual numbers to show? |
@mscdex Afaik Arrow Functions have identical overhead to regular functions. |
And regarding bind, to my knowledge it is specifically making the bound function that is slow, not running it. |
@Fishrock123 A quick google search turns up this jsperf. So at first glance it seems like it's not just the creation of bound functions that is slow? At any rate, if that jsperf is trustworthy, then arrow functions should be as fast as |
self.server = null; | ||
this.server.once('listening', () => { | ||
this.handle = this.server._handle; | ||
this.handle.onconnection = this.distribute.call(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this still be a bind (or another arrow function)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should not be a .call()
, otherwise the function will be immediately invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, forgot to wrap that in a () => {}
. One sec...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually...
What's better?
this.handle.onconnection = () => this.distribute.call(this);
or
this.handle.onconnection = this.distribute.bind(this);
One is one and done
and the other is an anon function that invokes .call each time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have access to this
, can't you just do the following?
this.handle.onconnection = () => this.distribute();
Although it looks like .distribute
expects some arguments, so .bind
might be more appropriate here (I'm not familiar with cluster internals, so that's really just speculative).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long day. @lucthev, you're 100% right. I'll revisit after some shuteye.
65e152c
to
3c8630e
Compare
Okay, looks like I've got all of the non-stacktrace changing (named functions like FWIW, passing all local tests |
self.send.apply(self, self._sendQueue[i]); | ||
self._sendQueue = undefined; | ||
for (var i = 0; i < this._sendQueue.length; i++) | ||
this.send.apply(this, this._sendQueue[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is worthy of a comment or not.
Very interestingly, rewriting this to this.send(this._sendQueue[i]);
blew up the dgram tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tflanagan Note that it is apply
and not call
, that is, it applies like so:
this.send.call(this, this._sendQueue[i][0], this._sendQueue[i][1], etc...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fishrock123 right, dumb moment, don't mind me. ( thank you ;) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do spread call now: this.send(...this._sendQueue[i])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@targos I remember reading that the spread operator isn't too friendly to v8 optimizations and to performance in general.
afa939a
to
9df8a7f
Compare
@jasnell I've reverted that constructor and also |
9df8a7f
to
6f20a17
Compare
I've just updated this PR to match master. /poke |
|
||
// Don't display any default messages | ||
var listeners = this.repl.rli.listeners('SIGINT').slice(0); | ||
this.repl.rli.removeAllListeners('SIGINT'); | ||
|
||
function exitDebugRepl() { | ||
var exitDebugRepl = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
?
Please don't force-push after a review the next time, it makes it very hard for me to track the new changes. |
I'm sorry - I'm running into errors with local tests, will commit fixes (wont force), in a moment |
This commit replaces trivial occurances of var self = this and .bind() where appropriate.
d5608cf
to
c780fcd
Compare
c780fcd
to
a1b9103
Compare
I'm done toying now :). Passes local tests fwiw (minus some flaky ones that happen on master too) |
LGTM |
Any reason those CI's aren't public? Would love to see if there some errors I can fix |
Yeah, we're currently testing the security fixes for next weeks release using the CI. Because the details of the fix are embargoed until the release we need to restrict access to the CI. Once we have the fixes fully tested the full CI will be made public again. Standard procedure when we have security updates pending! I think @rvagg just forgot to mention that in the security release notification posted the other day. |
Just looking at the CI now and it's almost all red. There are a ton of failures on this one unfortunately :-( .. I'm a bit tied up currently but here shortly I'll post some of the failures here for review |
Oh boy, sounds like some fun heading my way. ;) Thanks! -- I'll build it on my own boxes until then |
Not sure how far @jasnell got, but here are some OS X failures:
|
Thanks, @silverwind, I see those on my debian box too, I'm working on it. |
@silverwind .. thank you, @tflanagan sorry I didn't get the details like I said I would, ended up completely sidetracked for the rest of that day :-/ |
Just an update, I've been really busy these last couple months, I plan in fixing this soon. Its just a little low on priorities. The main deterrent is the lack of view rights on ci's. I don't see all the errors locally... |
@tflanagan ... no worries, completely understandable. The CI visibility is getting to be a major pain. Hopefully you'll be onboarded soon so you can access it. |
All failures on the Ubuntu 14.04 x64 box:
|
Given the changes here I'm going to mark this as a don't land on v4 for the time being. We may want to revisit this later /cc @thealphanerd |
What's the status on this one? |
7da4fd4
to
c7066fb
Compare
I'm going to close this for now as there has been no response in a month. Please feel free to reopen if you would like to pick this back up |
This commit replaces trivial occurances of var self = this and .bind()
where appropriate.
FWIW, passes local tests.
May be adding to this over the next day - this is the result of a couple simple greps.
This is in parallel to #3622.