Skip to content

Commit aacafae

Browse files
mcollinajuanarbol
authored andcommitted
buffer: increase Buffer.poolSize default to 64 KiB
The 8 KiB default has been unchanged since 2015. With the threshold check `size < (Buffer.poolSize >>> 1)`, this means allocations of 4 KiB or larger bypass the pool entirely — including 4 KiB itself, a common page and HTTP-frame size. Raising the default to 64 KiB extends pool coverage to ~32 KiB allocations, capturing common sizes used by HTTP parsers, stream chunks, and small file reads. Throughput improvements on workers-k=8 fs.readFileSync benchmarks (Linux/glibc) at the affected sizes, with no regressions elsewhere: file size | 8 KiB pool | 64 KiB pool | delta -----------+--------------+---------------+------- 4 KiB | 326k ops/s | 360k ops/s | +10% 8 KiB | 202k ops/s | 254k ops/s | +26% 16 KiB | 148k ops/s | 181k ops/s | +23% 64 KiB | 86k ops/s | 87k ops/s | ~ 1 MiB | 12k ops/s | 13k ops/s | ~ Cost: +56 KiB RSS per realm at startup. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #63597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent d4fc3f5 commit aacafae

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

doc/api/buffer.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ _may contain sensitive data_. Use [`buf.fill(0)`][`buf.fill()`] to initialize
865865
such `Buffer` instances with zeroes.
866866

867867
When using [`Buffer.allocUnsafe()`][] to allocate new `Buffer` instances,
868-
allocations less than `Buffer.poolSize >>> 1` (4KiB when default poolSize is used) are sliced
868+
allocations less than `Buffer.poolSize >>> 1` (32KiB when default poolSize is used) are sliced
869869
from a single pre-allocated `Buffer`. This allows applications to avoid the
870870
garbage collection overhead of creating many individually allocated `Buffer`
871871
instances. This approach improves both performance and memory usage by
@@ -1497,9 +1497,13 @@ console.log(Buffer.isEncoding(''));
14971497

14981498
<!-- YAML
14991499
added: v0.11.3
1500+
changes:
1501+
- version: REPLACEME
1502+
pr-url: https://github.com/nodejs/node/pull/63597
1503+
description: Default raised from 8192 to 65536.
15001504
-->
15011505

1502-
* Type: {integer} **Default:** `8192`
1506+
* Type: {integer} **Default:** `65536`
15031507

15041508
This is the size (in bytes) of pre-allocated internal `Buffer` instances used
15051509
for pooling. This value may be modified.

lib/buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const constants = ObjectDefineProperties({}, {
150150
},
151151
});
152152

153-
Buffer.poolSize = 8 * 1024;
153+
Buffer.poolSize = 64 * 1024;
154154
let poolSize, poolOffset, allocPool, allocBuffer;
155155

156156
function createPool() {

0 commit comments

Comments
 (0)