-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
fs.promises.readFile is 40% slower than fs.readFile #37583
Copy link
Copy link
Closed
Labels
benchmarkIssues and PRs related to Node.js benchmarks and benchmarking infrastructure.Issues and PRs related to Node.js benchmarks and benchmarking infrastructure.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.
Description
Activity
Metadata
Metadata
Assignees
Labels
benchmarkIssues and PRs related to Node.js benchmarks and benchmarking infrastructure.Issues and PRs related to Node.js benchmarks and benchmarking infrastructure.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.performanceIssues and PRs related to the performance of Node.js.Issues and PRs related to the performance of Node.js.
What steps will reproduce the bug?
Run this benchmark on a 1 MB file (
big.file):To create a 1 MB file (~40% slower):
To create a 20 KB file (~55% slower):
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
fs.promises.readFileshould perform similarly tofs.readFileWhat do you see instead?
Additional information
I suspect the cause is right here: https://github.com/nodejs/node/blob/master/lib/internal/fs/promises.js#L319-L339
Instead of creating a new
Bufferfor each chunk, it could allocate a single Buffer and write to that buffer. I don't thinkBuffer.concator temporary arrays are necessary.