From 0d4942836a3a3ca9085df087f2509216075197e4 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 3 Apr 2019 02:58:31 +0200 Subject: [PATCH] fs: improve readFile performance This increases the maximum buffer size per read to 256kb when using `fs.readFile`. This is important to improve the read performance for bigger files. Refs: https://github.com/nodejs/node/issues/25741 --- lib/internal/fs/read_file_context.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/read_file_context.js b/lib/internal/fs/read_file_context.js index 4961ee820a7e84..5397049b809149 100644 --- a/lib/internal/fs/read_file_context.js +++ b/lib/internal/fs/read_file_context.js @@ -79,7 +79,8 @@ class ReadFileContext { } else { buffer = this.buffer; offset = this.pos; - length = Math.min(kReadFileBufferLength, this.size - this.pos); + // Read up to 256kb. + length = Math.min(256 * 1024, this.size - this.pos); } const req = new FSReqCallback();