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

Optimizing Stats objects by creating Date objects lazily #137

Closed
fabiospampinato opened this issue Nov 25, 2023 · 2 comments · Fixed by nodejs/node#50908
Closed

Optimizing Stats objects by creating Date objects lazily #137

fabiospampinato opened this issue Nov 25, 2023 · 2 comments · Fixed by nodejs/node#50908

Comments

@fabiospampinato
Copy link

What is the problem this feature will solve?

Making fs.stat calls faster.

What is the feature you are proposing to solve the problem?

There seem to be 4 Date objects being created per Stats object:

https://github.com/nodejs/node/blob/7981e2ee642ae2b551201aa120560eb7d54fde03/lib/internal/fs/utils.js#L491-L494

I think those should be created lazily, and cached after they are read the first time for maximum backwards compatibility.

In a little local benchmark creating the equivalent number of Date objects in a loop seems responsible for roughly ~15% of the time that fs.statSync spends, and all those Date objects probably still left garbage to be collected behind that my little for loop wasn't accounting for.

I'd imagine it's pretty rare that somebody needs to read all 4 of those Date objects, and I actually never read any of those, so I'd expect this optimization to potentially translate to a ~15% speedup or near that for stat calls for many people.

What alternatives have you considered?

No reasonable alternatives, the only ones I can think of are using process['binding']('fs') directly, or switching to another runtime.

@aduh95 aduh95 transferred this issue from nodejs/node Nov 25, 2023
@H4ad
Copy link
Member

H4ad commented Jan 31, 2024

Based on nodejs/node#50908, can we close this issue?

@fabiospampinato
Copy link
Author

Yes, thanks everyone 😊

@avivkeller avivkeller moved this from Awaiting Triage to Done in Node.js feature requests Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants