Skip to content
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

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

IlyasShabi
Copy link
Contributor

@IlyasShabi IlyasShabi commented Oct 4, 2023

Local benchmark:

                                                  confidence improvement accuracy (*)   (**)  (***)
fs/bench-writevSync.js n=100000 type='invalid'        ***     125.24 %       ±2.51%   ±3.34%  ±4.37%
fs/bench-writevSync.js n=100000 type='valid'          ***     -0.26 %        ±3.07%   ±4.10%  ±5.34%

Ref: nodejs/performance#106

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Oct 4, 2023
@IlyasShabi
Copy link
Contributor Author

Feel free to suggest improvements in the benchmark file

@Uzlopak
Copy link
Contributor

Uzlopak commented Oct 4, 2023

Afaik in c++ returning a value is slower than modifying a variable passed as parameter (by ref).

fs.writeFileSync(path, 'Some content.');

const bench = common.createBenchmark(main, {
type: ['valid'],
Copy link
Member

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

Copy link
Contributor Author

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 🙏

lib/fs.js Outdated Show resolved Hide resolved
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;
Copy link
Member

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.

bench.start();
for (let i = 0; i < n; i++) {
try {
fs.writevSync(fd, [buffer]);
Copy link
Member

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.

lib/fs.js Outdated Show resolved Hide resolved
src/node_file.cc Outdated Show resolved Hide resolved
@mscdex
Copy link
Contributor

mscdex commented Oct 4, 2023

Did you swap the old and new node binary parameters when comparing the benchmarks or is that actually a 58% performance regression?

@anonrig anonrig added the needs-benchmark-ci PR that need a benchmark CI run. label Oct 4, 2023
src/node_file.cc Outdated Show resolved Hide resolved
@mscdex
Copy link
Contributor

mscdex commented Oct 5, 2023

FWIW the changes currently result in:

fs/bench-writevSync.js n=100000 type='valid'                -0.83 %       ±7.81% ±10.40% ±13.55%

I'm guessing this should instead be more about improving the error case?


bench.start();
for (let i = 0; i < n; i++) {
try {
Copy link
Member

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

fs.closeSync(fd);
break;
case 'invalid':
fd = tmpdir.resolve(`.non-existing-file-${process.pid}`);
Copy link
Member

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

@IlyasShabi IlyasShabi changed the title fs: improve writevSync performance fs: improve error performance of writevSync Oct 7, 2023
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 7, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 7, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. review wanted PRs that need reviews. labels Oct 8, 2023
@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 12, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 12, 2023
@nodejs-github-bot nodejs-github-bot merged commit bf0f078 into nodejs:main Oct 12, 2023
32 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in bf0f078

alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
targos pushed a commit that referenced this pull request Nov 11, 2023
debadree25 pushed a commit to debadree25/node that referenced this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. review wanted PRs that need reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants