-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
fs: two minor optimizations #14055
fs: two minor optimizations #14055
Conversation
@@ -552,10 +551,11 @@ fs.readFileSync = function(path, options) { | |||
var isUserFd = isFd(path); // file descriptor ownership | |||
var fd = isUserFd ? path : fs.openSync(path, options.flag || 'r', 0o666); | |||
|
|||
tryStatSync(fd, isUserFd); |
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.
Now that TF+I are in, can we start inlining all of these try*
functions?
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.
At least in a recently run benchmark (v8 5.8) it still seemed like it's a tiny bit better to keep them around. I suggest to wait until 6.0 has landed and if it's good to inline them, I'd make a single PR for all of them.
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.
Ack, since it's an patch level enhancement that should land in v8.x
, although it will probably be relevant for 1 minor node8
release.
@@ -520,7 +520,6 @@ function tryStatSync(fd, isUserFd) { | |||
} finally { |
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 guess it was written like this for performance. If not, isn't cleaner to use catch
and get rid of the threw variable?
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 am about to open a separate PR that deals with lots of those :D
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.
Get ready to run benchmarks then :) as I remember that some of these changes (finally
-> catch
) were rejected in the past. I think it was on timers.
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.
Out of my perspective the main issue is that the error has to be thrown again.
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.
Hm, when running the benchmark it does not seem to be a significant change, so it would be more churn than anything else.
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.
@BridgeAR please note that the performance profile of try/catch/finally changed quite a bit since the code was added most likely :)
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.
Of course but I ran the benchmarks with changing these to try catch and it did not show changed numbers. Therefore I think it's mainly churn to change it.
@@ -552,10 +551,11 @@ fs.readFileSync = function(path, options) { | |||
var isUserFd = isFd(path); // file descriptor ownership | |||
var fd = isUserFd ? path : fs.openSync(path, options.flag || 'r', 0o666); | |||
|
|||
tryStatSync(fd, isUserFd); |
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.
Ack, since it's an patch level enhancement that should land in v8.x
, although it will probably be relevant for 1 minor node8
release.
@@ -552,10 +551,11 @@ fs.readFileSync = function(path, options) { | |||
var isUserFd = isFd(path); // file descriptor ownership | |||
var fd = isUserFd ? path : fs.openSync(path, options.flag || 'r', 0o666); | |||
|
|||
tryStatSync(fd, isUserFd); | |||
// Use stats array directly to avoid creating an fs.Stats instance just for | |||
// our internal use. | |||
var size; |
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.
does a trinary with assign to const perform better?
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.
There is not really a measurable difference.
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.
🤷♂️ never mind then
* tryStatSync should not return any value If the function threw, it would never reach that code path. * only use try catch if necessary lchmodSync does not need the second try catch in most cases. PR-URL: nodejs#14055 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Extra quick sanity: https://ci.nodejs.org/job/node-test-commit-linuxone/7168/ |
* tryStatSync should not return any value If the function threw, it would never reach that code path. * only use try catch if necessary lchmodSync does not need the second try catch in most cases. PR-URL: #14055 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
* tryStatSync should not return any value If the function threw, it would never reach that code path. * only use try catch if necessary lchmodSync does not need the second try catch in most cases. PR-URL: #14055 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
* tryStatSync should not return any value If the function threw, it would never reach that code path. * only use try catch if necessary lchmodSync does not need the second try catch in most cases. PR-URL: #14055 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Should this be backported to |
ping re: v6.x |
I will open a PR to backport this soon. |
ping @BridgeAR |
When looking at it again there is little benefit for backporting, so I just changed the label accordingly. |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs