Skip to content

Commit 28ff3bd

Browse files
committed
stream: default hwm based on Buffer.poolSize
Make streams default HWM correspond to Buffer.poolSize.
1 parent a932430 commit 28ff3bd

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

doc/api/stream.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ changes:
23602360
* `options` {Object}
23612361
* `highWaterMark` {number} Buffer level when
23622362
[`stream.write()`][stream-write] starts returning `false`. **Default:**
2363-
`16384` (16 KB), or `16` for `objectMode` streams.
2363+
[`Buffer.poolSize`][], or `16` for `objectMode` streams.
23642364
* `decodeStrings` {boolean} Whether to encode `string`s passed to
23652365
[`stream.write()`][stream-write] to `Buffer`s (with the encoding
23662366
specified in the [`stream.write()`][stream-write] call) before passing
@@ -3623,6 +3623,7 @@ contain multi-byte characters.
36233623
[`'end'`]: #event-end
36243624
[`'finish'`]: #event-finish
36253625
[`'readable'`]: #event-readable
3626+
[`Buffer.poolSize`]: #class-property-bufferpoolsize
36263627
[`Duplex`]: #class-streamduplex
36273628
[`EventEmitter`]: events.md#class-eventemitter
36283629
[`Readable`]: #class-streamreadable

lib/internal/fs/streams.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
Array,
55
FunctionPrototypeBind,
66
MathMin,
7+
MathMax,
78
ObjectDefineProperty,
89
ObjectSetPrototypeOf,
910
PromisePrototypeThen,
@@ -152,7 +153,7 @@ function ReadStream(path, options) {
152153
// A little bit bigger buffer and water marks by default
153154
options = copyObject(getOptions(options, {}));
154155
if (options.highWaterMark === undefined)
155-
options.highWaterMark = 64 * 1024;
156+
options.highWaterMark = MathMax(Buffer.poolSize, 64 * 1024);
156157

157158
if (options.autoDestroy === undefined) {
158159
options.autoDestroy = false;

lib/internal/streams/state.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
MathFloor,
55
NumberIsInteger,
66
} = primordials;
7+
const { Buffer } = require('buffer');
78

89
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
910

@@ -13,7 +14,7 @@ function highWaterMarkFrom(options, isDuplex, duplexKey) {
1314
}
1415

1516
function getDefaultHighWaterMark(objectMode) {
16-
return objectMode ? 16 : 16 * 1024;
17+
return objectMode ? 16 : Buffer.poolSize;
1718
}
1819

1920
function getHighWaterMark(state, options, duplexKey, isDuplex) {

0 commit comments

Comments
 (0)