fs: improve error performance for fsyncSync#49880
fs: improve error performance for fsyncSync#49880nodejs-github-bot merged 9 commits intonodejs:mainfrom
fsyncSync#49880Conversation
fsyncSyncfsyncSync
lib/internal/fs/sync.js
Outdated
| } | ||
|
|
||
| function fsync(fd) { | ||
| fd = getValidatedFd(fd); |
There was a problem hiding this comment.
Nit: If you moved this function to c++, it would improve the happy path (existing file)
There was a problem hiding this comment.
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.
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.
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
joyeecheung
left a comment
There was a problem hiding this comment.
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
|
|
||
| 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.
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.
@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