-
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: improve error performance of writevSync #50038
Conversation
Feel free to suggest improvements in the benchmark file |
Afaik in c++ returning a value is slower than modifying a variable passed as parameter (by ref). |
benchmark/fs/bench-writevSync.js
Outdated
fs.writeFileSync(path, 'Some content.'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['valid'], |
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.
Please add an invalid type to benchmarks
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.
@anonrig I would appreciate help creating a good bench script for my first PR 🙏
src/node_file.cc
Outdated
uv_fs_write, fd, *iovs, iovs.length(), pos); | ||
} else { // writeBuffers(fd, chunks, pos, undefined, ctx) | ||
CHECK_EQ(argc, 5); | ||
} else { | ||
FSReqWrapSync req_wrap_sync; |
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.
This line needs to be updated.
benchmark/fs/bench-writevSync.js
Outdated
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
try { | ||
fs.writevSync(fd, [buffer]); |
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.
In order to remove dead code elimination store the result of this operation and assert it when the benchmark finishes.
Did you swap the old and new node binary parameters when comparing the benchmarks or is that actually a 58% performance regression? |
c522003
to
1f60944
Compare
FWIW the changes currently result in:
I'm guessing this should instead be more about improving the error case? |
1f60944
to
3c2e4ad
Compare
benchmark/fs/bench-writevSync.js
Outdated
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
try { |
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 don't need a try/catch on valid part
benchmark/fs/bench-writevSync.js
Outdated
fs.closeSync(fd); | ||
break; | ||
case 'invalid': | ||
fd = tmpdir.resolve(`.non-existing-file-${process.pid}`); |
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.
This is not a file descriptor. The variable name suggests fd
3c2e4ad
to
2a2ca8b
Compare
2a2ca8b
to
4babf4d
Compare
Landed in bf0f078 |
PR-URL: nodejs#50038 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: #50038 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: nodejs#50038 Refs: nodejs/performance#106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Local benchmark:
Ref: nodejs/performance#106