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

os: improve performance of hostname and homedir #50037

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Oct 4, 2023

This PR improves the performance of the homedir and hostname.

                          confidence improvement accuracy (*)   (**)  (***)
os/hostname.js n=1000000        ***     37.28 %       ±1.16% ±1.54% ±2.01%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 1 comparisons, you can thus expect the following amount of false-positive results:
  0.05 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.01 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)
                        confidence improvement accuracy (*)   (**)  (***)
os/homedir.js n=1000000        ***     60.71 %       ±4.49% ±6.00% ±7.88%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 1 comparisons, you can thus expect the following amount of false-positive results:
  0.05 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.01 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)
                      confidence improvement accuracy (*)   (**)  (***)
os/uptime.js n=100000        ***      0.69 %       ±0.19% ±0.26% ±0.33%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 1 comparisons, you can thus expect the following amount of false-positive results:
  0.05 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.01 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. os Issues and PRs related to the os subsystem. labels Oct 4, 2023
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@nodejs-github-bot
Copy link
Collaborator

lib/os.js Outdated Show resolved Hide resolved
lib/os.js Outdated Show resolved Hide resolved
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 4, 2023

@H4ad
@mscdex

Removed the caching.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 4, 2023

Updated the benchmark in initial post.

We should discuss the caching. But this is the minimal consensus, which should be mergable.

@Uzlopak Uzlopak changed the title os: cache homedir, remove getCheckedFunction os: improve performance of hostname and homedir, remove getCheckedFunction Oct 4, 2023
@H4ad
Copy link
Member

H4ad commented Oct 4, 2023

@Uzlopak do we have an idea how much time it takes in ms to get the homedir?

If it's quick, I think we can land without a cache, the improvements are good enough.

If it's slow, I think adding caching will not be bad, accords to docs: https://docs.libuv.org/en/v1.x/misc.html#c.uv_os_homedir doesn't look like this information will change during the execution of the process. We only need to worry about the snapshot.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 4, 2023

I dont know how to measure the lookup time

@H4ad
Copy link
Member

H4ad commented Oct 4, 2023

Code:

const {homedir, hostname} = require('os')

let now = performance.now();
let value = homedir();
console.log(`Diff: ${ performance.now() - now }ms`);

now = performance.now();
value = hostname();
console.log(`Diff: ${ performance.now() - now }ms`);

Output:

Diff: 0.045215003192424774ms
Diff: 0.01658099889755249ms

Since we don't have any hot path calling this code multiple times, I think we can skip caching to not add complexity without a good reason.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 4, 2023

ah, you mean like that.

Maybe programms like npm or pnpm need homedir more excessively.

@mscdex
Copy link
Contributor

mscdex commented Oct 4, 2023

Package managers are more likely to have I/O or compression/decompression be their bottleneck rather than something like os.homedir().

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 4, 2023

@anonrig can you please add the author-ready tag?

@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 4, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@nodejs-github-bot
Copy link
Collaborator

lib/os.js Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 6, 2023

@mscdex
If #49990 lands i want to anyway split to avoid an additional hideStackFrames call.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 10, 2023

@mcollina can i interest you into reviewing this PR?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 13, 2023

@anonrig
What about now?

@anonrig
Copy link
Member

anonrig commented Oct 13, 2023

@anonrig

What about now?

The CI is locked. It seems the errors are fixed in main. Can you rebase and force push?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 13, 2023

@anonrig
done

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 14, 2023

@anonrig
can it be merged?

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 14, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 14, 2023
@nodejs-github-bot
Copy link
Collaborator

@Uzlopak Uzlopak changed the title os: improve performance of hostname and homedir, remove getCheckedFunction os: improve performance of hostname and homedir Oct 14, 2023
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 15, 2023

@anonrig can you give the CI some love please? :D

@nodejs-github-bot
Copy link
Collaborator

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 15, 2023

@anonrig
Seems that the checks pass?

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 15, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 15, 2023
@nodejs-github-bot nodejs-github-bot merged commit 0f0dd1a into nodejs:main Oct 15, 2023
25 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 0f0dd1a

@Uzlopak Uzlopak deleted the os-cache-homedir branch October 15, 2023 08:58
kumarrishav pushed a commit to kumarrishav/node that referenced this pull request Oct 16, 2023
PR-URL: nodejs#50037
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Copy link

@maanu1234 maanu1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

@maanu1234 maanu1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@maanu1234

This comment was marked as off-topic.

alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
PR-URL: nodejs#50037
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
targos pushed a commit that referenced this pull request Nov 11, 2023
PR-URL: #50037
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
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. needs-ci PRs that need a full CI run. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants