Skip to content

os: improve performance of hostname and homedir - #50037

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Uzlopak:os-cache-homedir
Oct 15, 2023
Merged

os: improve performance of hostname and homedir#50037
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Uzlopak:os-cache-homedir

Conversation

@Uzlopak

@UzlopakUzlopak commented Oct 4, 2023

Copy link
Copy Markdown
Contributor

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-botnodejs-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
@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadlib/os.js Outdated
Comment threadlib/os.js Outdated
@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

@H4ad
@mscdex

Removed the caching.

H4ad
H4ad approved these changes Oct 4, 2023
@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

Updated the benchmark in initial post.

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

@UzlopakUzlopak changed the title os: cache homedir, remove getCheckedFunctionos: improve performance of hostname and homedir, remove getCheckedFunctionOct 4, 2023
@H4ad

H4ad commented Oct 4, 2023

Copy link
Copy Markdown
Member

@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
Copy Markdown
ContributorAuthor

I dont know how to measure the lookup time

@H4ad

H4ad commented Oct 4, 2023

Copy link
Copy Markdown
Member

Code:

const{homedir, hostname}=require('os')letnow=performance.now();letvalue=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
Copy Markdown
ContributorAuthor

ah, you mean like that.

Maybe programms like npm or pnpm need homedir more excessively.

@mscdex

Copy link
Copy Markdown
Contributor

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

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

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

@anonriganonrig 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-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 4, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadlib/os.js Outdated
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

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

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

@mcollina can i interest you into reviewing this PR?

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

@anonrig
What about now?

@anonrig

Copy link
Copy Markdown
Member

@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
Copy Markdown
ContributorAuthor

@anonrig
done

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

@anonrig
can it be merged?

@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 14, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 14, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@UzlopakUzlopak changed the title os: improve performance of hostname and homedir, remove getCheckedFunctionos: improve performance of hostname and homedirOct 14, 2023
@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Uzlopak

Copy link
Copy Markdown
ContributorAuthor

@anonrig
Seems that the checks pass?

@anonriganonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 15, 2023
@nodejs-github-botnodejs-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:mainOct 15, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 0f0dd1a

@Uzlopak
Uzlopak deleted the os-cache-homedir branch October 15, 2023 08:58

@maanu1234maanu1234 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

@maanu1234maanu1234 left a comment

Copy link
Copy Markdown

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.

targos pushed a commit that referenced this pull request Nov 11, 2023
PR-URL: #50037
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@targostargos mentioned this pull request Nov 12, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.needs-ciPRs that need a full CI run.osIssues and PRs related to the os subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@Uzlopak@nodejs-github-bot@H4ad@mscdex@anonrig@maanu1234