fs: minor refactoring#1870
Conversation
311c3e4 to
b926718
Compare
|
Some points:
Other than that LGTM. |
|
@benjamingr The points I mentioned in the PR would be good enough to be in the commit messages, right? |
|
Right. I think so - check out some other PRs. |
There was a problem hiding this comment.
Maybe make this const while you're here.
c18484f to
40d4c54
Compare
|
@benjamingr @bnoordhuis I updated the PR as per the suggestions. Please review. |
40d4c54 to
5a5fc58
Compare
1. Changing `Bad arguments` error messages to a more helpful message `options should either be an object or a string`. 2. Made braces consistent. 3. Returning meaningful error message from `fs_event_wrap`'s `FSEvent`'s `Start` function.
5a5fc58 to
de2a7f1
Compare
`nullCheckCallNT` function is not necessary, as we can directly pass `callback` and `er` to `process.nextTick`
|
@benjamingr @bnoordhuis I included another commit which does very minor refactoring stuff. Please let me know if that commit is not worth sending in. I ll pull that out. |
There was a problem hiding this comment.
Would prefer encoding to be its own var statement.
0f381df to
d725865
Compare
|
I included a commit which makes |
32d9610 to
fcfd07e
Compare
|
@benjamingr @chrisdickinson @Fishrock123 I wrote a benchmark (this may not be good, please review and give feedback if you have time) and I found that the The first run was from the latest |
|
I'm not comfortable with the FSReqWrap change. When I implemented that there were nuances about where it needed to be called. I'll want to review that change in more detail. |
|
@trevnorris Are you talking about this line? It was just moved up, because inside the |
|
@thefourtheye I see that now. Wrote my first comment from my phone and it wasn't easy to see the changes completely. Okay, LGTM. |
|
@trevnorris No problem. Thanks for reviewing :-) |
There was a problem hiding this comment.
Reading and assigning to arguments at the same time is a deopt.
Not sure if this matters.
Edit: I was wrong, it is optimized in the strict mode, and in sloppy mode it is deoptimized even with a var callback if the variable name is the same as one of the arguments.
There was a problem hiding this comment.
it is easy to prevent just by renaming the parameter to something like callback_ and leaving the var keyword where it was.
There was a problem hiding this comment.
Yup, there are many places in the file where we do this. So, I am doing this in a commit.
There was a problem hiding this comment.
even if writing to /dev/null I doubt it could be run enough to notice a difference. and from the looks of it, nothing that way was actually changed. Just removed the unnecessary var.
There was a problem hiding this comment.
I tested it (with v8 4.2) and it seems that I was wrong about the deopt, sorry.
'use strict' changes some things related to arguments handling, and it has an effect on the optimization.
@petkaantonov this should be probably mentioned in that example.
There was a problem hiding this comment.
@thefourtheye I'm using this test: petkaantonov/bluebird/wiki/Optimization-killers#1-tooling with recent iojs.
There was a problem hiding this comment.
@ChALkeR I tried something like this
function containsWith(a_) {
var a = arguments[0] + 1;
}
function containsWith(a) {
a = arguments[0] + 1;
}
but it still says the function is not optimized for both the cases.
There was a problem hiding this comment.
@ChALkeR it's actually a wikipage, you should be able to edit it :P
There was a problem hiding this comment.
I updated the PR with a commit which will use a different variable name.
There was a problem hiding this comment.
but it still says the function is not optimized for both the cases.
Have you enabled 'use strict' for the file or for the function?
function unoptimized0(a, b) {
b = arguments[arguments.length - 1] + 1;
return b * 1;
}
function unoptimized1(a, b) {
var b = arguments[arguments.length - 1] + 1;
return b * 1;
}
function optimized0(a, b) {
'use strict';
b = arguments[arguments.length - 1] + 1;
return b * 1;
}
function optimized1(a, b) {
'use strict';
var b = arguments[arguments.length - 1] + 1;
return b * 1;
}Edit: There was an error in the last function name.
f6cb789 to
858ee0d
Compare
There was a problem hiding this comment.
glad there are others around to clean up my mess. thanks for catching it.
There was a problem hiding this comment.
looks like the {} were added for stylistic reasons?
There was a problem hiding this comment.
@trevnorris Yup, when I was preparing the patch, I am not sure why, but linter was complaining about throwOptionsError being in that position. I had to use {} to fix it. Now, linter is fine without {}. Shall I revert it?
There was a problem hiding this comment.
@thefourtheye it is probably this eslint bug again. We already encountered it in #1742
There was a problem hiding this comment.
@targos Yup, that looks more like it. But, I just locally ran make lint without the braces and it is fine. Don't know why. I think its better to leave it as it is now.
|
think the final list of commits should be:
If can do that if you'd like, or you can take care of it. Either way, LGTM. |
858ee0d to
365bc72
Compare
|
@trevnorris I squashed the commits and edited the commit messages a little bit. Please have a look at them. |
|
Looks great. Just want to run CI one last time for sanity sake then I'll land these. |
|
There were a total of 6 failures (1 on armv7-wheezy, 5 on win2008r2). None of them look related to this patch. Going to land. |
1. Change "Bad arguments" error messages to a more helpful message "options should either be an object or a string". 2. Make braces consistent. 3. Return meaningful error message from fs_event_wrap's FSEvent's Start function. PR-URL: nodejs#1870 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
`nullCheckCallNT()` function is not necessary, as we can directly pass `callback` and `er` to `process.nextTick()`. PR-URL: nodejs#1870 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Remove `inStatWatchers` function and make `statWatchers` a `Map`. PR-URL: nodejs#1870 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1. Remove a few unnecessary variables to reduce LoC. 2. Remove redundant `var` definitions of variables in same function. 3. Refactor variables which are defined inside a block and used outside as well. 4. Refactor effect-less code. 5. In `rethrow` function, instead of assigning to `err` and throwing `err` directly throw `backtrace` object. 6. Reassign a defined parameter while also mentioning arguments in the body is one of the optimization killers. So, changing `callback` to `callback_` and declaring a new variable called `callback` in the body. PR-URL: nodejs#1870 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Make SyncWriteStream non-enumerable since it's only for internal use. PR-URL: nodejs#1870 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
|
Landed in 09f2a67, 67a11b9, 8841132, a011c32 and 53a4eb3 with a few commit message grammatical changes. Thanks much for the work. Quick note, it's preferred to use the present in commit messages. e.g. "Change parameters" instead of "Changing parameters". Also preferred to not use personal pronouns. e.g. "New function foo() can return value x" instead of "We can return the value x from the new function foo()". |
We are getting rid of `inStatWatchers` function and making `statWatchers` a `Map`.
1. Removed a few unnecessary variables to reduce LoC 2. Removed redundant `var` definitions of variables in same function 3. Refactored variables which are defined inside a block and used outside as well 4. Refactored effect-less code 5. In `rethrow` function, instead of assigning to `err` and throwing `err`, we can directly throw `backtrace` object itself. 6. Reassigning a defined parameter while also mentioning arguments in the body is one of the optimization killers. So, changing `callback` to `callback_` and declaring a new variable called `callback` in the body.
As `SyncWriteStream` is only for internal use, it would be better
if it is non-enumerable, so that a simple `console.log(require('fs'))`
will not reveal it.
|
@trevnorris Thanks :) I ll remember the suggestions for the next time :) |
Bad argumentsmessages tooptions should either be an object or a stringand returning meaningful error message fromfs_event_wrap'sFSEvent'sStartfunction.nullCheckCallNTfunction is not necessary, as we can directly passcallbackandertoprocess.nextTickinStatWatchersfunction and makingstatWatchersaMap.rethrowfunction, instead of assigning toerrand throwingerr, we can directly throwbacktraceitself.SyncWriteStreamis only for internal use, it would be better if it is non-enumerable, so that a simpleconsole.log(require('fs'))will not reveal it.