Skip to content

Commit

Permalink
fs: improve fsPromises writeFile performance
Browse files Browse the repository at this point in the history
Increase the write chunk size in fsPromises writeFile
to improve performance.

PR-URL: nodejs#37610
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Linkgoron authored and MoritzLoewenstein committed Sep 4, 2021
1 parent 55493f2 commit d51c40c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/internal/fs/promises.js
@@ -1,7 +1,5 @@
'use strict';

const kWriteFileMaxChunkSize = 2 ** 14;

const {
ArrayPrototypePush,
Error,
Expand Down Expand Up @@ -40,6 +38,7 @@ const {
kMaxUserId,
kReadFileBufferLength,
kReadFileUnknownBufferLength,
kWriteFileMaxChunkSize
},
copyObject,
getDirents,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/utils.js
Expand Up @@ -125,6 +125,7 @@ const kIoMaxLength = 2 ** 31 - 1;
// blocking other threads in case the available threads are all in use.
const kReadFileUnknownBufferLength = 64 * 1024;
const kReadFileBufferLength = 512 * 1024;
const kWriteFileMaxChunkSize = 512 * 1024;

const kMaxUserId = 2 ** 32 - 1;

Expand Down Expand Up @@ -835,6 +836,7 @@ module.exports = {
kMaxUserId,
kReadFileBufferLength,
kReadFileUnknownBufferLength,
kWriteFileMaxChunkSize
},
assertEncoding,
BigIntStats, // for testing
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-promises-file-handle-writeFile.js
Expand Up @@ -34,7 +34,7 @@ async function validateWriteFile() {
async function doWriteAndCancel() {
const filePathForHandle = path.resolve(tmpDir, 'dogs-running.txt');
const fileHandle = await open(filePathForHandle, 'w+');
const buffer = Buffer.from('dogs running'.repeat(10000), 'utf8');
const buffer = Buffer.from('dogs running'.repeat(512 * 1024), 'utf8');
const controller = new AbortController();
const { signal } = controller;
process.nextTick(() => controller.abort());
Expand Down

0 comments on commit d51c40c

Please sign in to comment.