From 0876cf33e8940702e3d09330bc87c5650b466678 Mon Sep 17 00:00:00 2001 From: Nitzan Uziely Date: Fri, 5 Mar 2021 14:37:57 +0200 Subject: [PATCH] fs: improve fsPromises writeFile performance Increase the write chunk size in fsPromises writeFile to improve performance. --- lib/internal/fs/promises.js | 2 +- test/parallel/test-fs-promises-file-handle-writeFile.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 32ad2123d47db0..bb7a6396189967 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -7,7 +7,7 @@ const kIoMaxLength = 2 ** 31 - 1; // Note: This is different from kReadFileBufferLength used for non-promisified // fs.readFile. const kReadFileMaxChunkSize = 2 ** 14; -const kWriteFileMaxChunkSize = 2 ** 14; +const kWriteFileMaxChunkSize = 512 * 1024; const { ArrayPrototypePush, diff --git a/test/parallel/test-fs-promises-file-handle-writeFile.js b/test/parallel/test-fs-promises-file-handle-writeFile.js index bd90a79149b5f1..7ad1beb4bcdd7b 100644 --- a/test/parallel/test-fs-promises-file-handle-writeFile.js +++ b/test/parallel/test-fs-promises-file-handle-writeFile.js @@ -30,7 +30,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());