Skip to content

Commit

Permalink
stream: default hwm based on Buffer.poolSize
Browse files Browse the repository at this point in the history
Make streams default HWM correspond to Buffer.poolSize.
  • Loading branch information
ronag committed Oct 19, 2021
1 parent a932430 commit 28ff3bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ changes:
* `options` {Object}
* `highWaterMark` {number} Buffer level when
[`stream.write()`][stream-write] starts returning `false`. **Default:**
`16384` (16 KB), or `16` for `objectMode` streams.
[`Buffer.poolSize`][], or `16` for `objectMode` streams.
* `decodeStrings` {boolean} Whether to encode `string`s passed to
[`stream.write()`][stream-write] to `Buffer`s (with the encoding
specified in the [`stream.write()`][stream-write] call) before passing
Expand Down Expand Up @@ -3623,6 +3623,7 @@ contain multi-byte characters.
[`'end'`]: #event-end
[`'finish'`]: #event-finish
[`'readable'`]: #event-readable
[`Buffer.poolSize`]: #class-property-bufferpoolsize
[`Duplex`]: #class-streamduplex
[`EventEmitter`]: events.md#class-eventemitter
[`Readable`]: #class-streamreadable
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
Array,
FunctionPrototypeBind,
MathMin,
MathMax,
ObjectDefineProperty,
ObjectSetPrototypeOf,
PromisePrototypeThen,
Expand Down Expand Up @@ -152,7 +153,7 @@ function ReadStream(path, options) {
// A little bit bigger buffer and water marks by default
options = copyObject(getOptions(options, {}));
if (options.highWaterMark === undefined)
options.highWaterMark = 64 * 1024;
options.highWaterMark = MathMax(Buffer.poolSize, 64 * 1024);

if (options.autoDestroy === undefined) {
options.autoDestroy = false;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/streams/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
MathFloor,
NumberIsInteger,
} = primordials;
const { Buffer } = require('buffer');

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

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

function getDefaultHighWaterMark(objectMode) {
return objectMode ? 16 : 16 * 1024;
return objectMode ? 16 : Buffer.poolSize;
}

function getHighWaterMark(state, options, duplexKey, isDuplex) {
Expand Down

0 comments on commit 28ff3bd

Please sign in to comment.