Skip to content

fs: improve fsPromises writeFile performance

Currently the writeFile in fs/promises is around three times slower than the non-promisifed version (at least, when I tested various files on my machine). The reason, I believe, is mainly because of chunking, which does not exist at all in the regular version (see writeAll in fs.js) , and is rather small (IMO) in writeFile.

I've increased kWriteFileMaxChunkSize from 2**14 to 512*1024, which is the same as the read buffer size in read_file_context in https://github.com/nodejs/node/pull/37608. This made both writeFile methods essentially the same (the fs/promises is slightly slower in my testing).

It might be correct to also add chunking to the fs version, similar to readFile (https://github.com/nodejs/node/pull/17054 and https://github.com/nodejs/node/issues/25741) - but I believe that should be a different issue with more discussion.

edit: second commit contains fs.promises.writeFile benchmark

Merge request reports

Loading