-
Notifications
You must be signed in to change notification settings - Fork 30k
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 promise based readFile performance for big files #44295
fs: improve promise based readFile performance for big files #44295
Conversation
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.
lgtm
744bbd9
to
e72802b
Compare
We might consider a similar fix for #41435. If I checked correct, it outperforms the regular readFile variant for big files. |
Does this also impact "old" callback- based readFile? |
No. This is solely about the promise based readFile with encodings. The non encoding part is also not impacted.
I ran the benchmark on our machines and there seems to be a weird effect for some file sizes where there's a performance drop. I guess it has to do with how V8 handles some things internally. |
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.
lgtm
@BridgeAR are you planning to do the same for the sync and callback versions too? |
3f028d6
to
83562ca
Compare
This significantly reduces the peak memory for the promise based readFile operation by reusing a single memory chunk after each read and strinigifying that chunk immediately. Signed-off-by: Ruben Bridgewater <[email protected]>
4d4997b
to
6c92996
Compare
@mcollina I suggest to merge this and I am looking into the other part afterwards. |
Yes, let's do it. |
Commit Queue failed- Loading data for nodejs/node/pull/44295 ✔ Done loading data for nodejs/node/pull/44295 ----------------------------------- PR info ------------------------------------ Title fs: improve promise based readFile performance for big files (#44295) Author Ruben Bridgewater (@BridgeAR) Branch BridgeAR:improve-fs-promises-readfile -> nodejs:main Labels fs Commits 1 - fs: improve promise based readFile performance for big files Committers 1 - Ruben Bridgewater PR-URL: https://github.com/nodejs/node/pull/44295 Reviewed-By: Matteo Collina Reviewed-By: James M Snell ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/44295 Reviewed-By: Matteo Collina Reviewed-By: James M Snell -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - fs: improve promise based readFile performance for big files ℹ This PR was created on Fri, 19 Aug 2022 15:12:52 GMT ✔ Approvals: 2 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/44295#pullrequestreview-1080779016 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/44295#pullrequestreview-1087869731 ✔ Last GitHub CI successful ℹ Last Benchmark CI on 2022-08-20T10:00:08Z: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1176/ ℹ Last Full PR CI on 2022-10-06T13:18:58Z: https://ci.nodejs.org/job/node-test-pull-request/47101/ - Querying data for job/node-test-pull-request/47101/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/3198926242 |
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.
lgtm
Landed in d3dd49f |
This significantly reduces the peak memory for the promise based readFile operation by reusing a single memory chunk after each read and strinigifying that chunk immediately. Signed-off-by: Ruben Bridgewater <[email protected]> PR-URL: #44295 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
This significantly reduces the peak memory for the promise
based readFile operation by reusing a single memory chunk after
each read and strinigifying that chunk immediately.
Refs: #44239 (reply in thread)
Signed-off-by: Ruben Bridgewater [email protected]
Benchmark with a few runs: