-
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
fs: improve error performance for fsyncSync
#49880
Conversation
fsyncSync
fsyncSync
lib/internal/fs/sync.js
Outdated
@@ -88,6 +88,11 @@ function close(fd) { | |||
return binding.closeSync(fd); | |||
} | |||
|
|||
function fsync(fd) { | |||
fd = getValidatedFd(fd); |
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.
Nit: If you moved this function to c++, it would improve the happy path (existing file)
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.
That's a good opinion!
I think you just need to add CHECK_GE(fd,0) to C++.
Do you have a better idea?
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.
We need to replicate the behavior of getValidatedFd
in C++ and throw the correct error.
const getValidatedFd = hideStackFrames((fd, propName = 'fd') => {
if (ObjectIs(fd, -0)) {
return 0;
}
validateInt32(fd, propName, 0);
return fd;
});
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 added the implementation in C++.
I'm not sure if this implementation is correct.
also I updated the benchmark.
When I check it locally, the performance is strange.
Please review again.
e1ebe02
to
c710f94
Compare
764386f
to
ad76d06
Compare
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 the diff can be a lot simpler if you just change the sync branch of the original implementations instead of repeating the code in a new binding..(and if you only introduce new bindings, the original sync branch would be dead code..) also I think this breaks --trace-sync-io?
Hey @pluris can you rebase this pull request? You'll see that |
src/node_file.cc
Outdated
@@ -116,6 +116,24 @@ inline int64_t GetOffset(Local<Value> value) { | |||
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1; | |||
} | |||
|
|||
inline int GetValidatedFd(Environment* env, Local<Value> value) { | |||
if (!value->IsInt32()) { | |||
env->isolate()->ThrowException(ERR_INVALID_ARG_TYPE( |
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 this should be a ValidateInt32
if we want to start moving the validation to C++. Also this is not entirely on-par with the original implementation - the original implementation would print the value in a readable format in the case it's not a number, and this does not give any information about the invalid argument, which would make it harder for users to fix the error. We could also just don't move the error validation code now and leave it in JS if it's not ready to take on implementing proper argument validation + printing in C++.
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.
@joyeecheung Thank you for your comment.
You are right. As you said, I think we need to think more about the implementation of GetValidateFd()
. First, I will remove this addition to C++ and change it to the original implementation.
cfd9354
to
fcffde8
Compare
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
Landed in fbd08ec |
PR-URL: #49880 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: nodejs#49880 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: #49880 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Refs: nodejs/performance#106