Skip to content

Commit ba72570

Browse files
mafintoshisaacs
authored andcommitted
stream: change default hwm for objectMode to 16
1 parent ee695e9 commit ba72570

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/api/stream.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ SimpleProtocol.prototype._read = function(n) {
871871
* `options` {Object}
872872
* `highWaterMark` {Number} The maximum number of bytes to store in
873873
the internal buffer before ceasing to read from the underlying
874-
resource. Default=16kb
874+
resource. Default=16kb, or 16 for `objectMode` streams
875875
* `encoding` {String} If specified, then buffers will be decoded to
876876
strings using the specified encoding. Default=null
877877
* `objectMode` {Boolean} Whether this stream should behave
@@ -987,7 +987,7 @@ how to implement Writable streams in your programs.
987987

988988
* `options` {Object}
989989
* `highWaterMark` {Number} Buffer level when [`write()`][] starts
990-
returning false. Default=16kb
990+
returning false. Default=16kb, or 16 for `objectMode` streams
991991
* `decodeStrings` {Boolean} Whether or not to decode strings into
992992
Buffers before passing them to [`_write()`][]. Default=true
993993

lib/_stream_readable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function ReadableState(options, stream) {
3636
// the point at which it stops calling _read() to fill the buffer
3737
// Note: 0 is a valid value, means "don't call _read preemptively ever"
3838
var hwm = options.highWaterMark;
39-
this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
39+
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
40+
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
4041

4142
// cast to ints.
4243
this.highWaterMark = ~~this.highWaterMark;

lib/_stream_writable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function WritableState(options, stream) {
4444
// Note: 0 is a valid value, means that we always return false if
4545
// the entire buffer is not flushed immediately on write()
4646
var hwm = options.highWaterMark;
47-
this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
47+
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
48+
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
4849

4950
// object stream flag to indicate whether or not this stream
5051
// contains buffers or objects.

0 commit comments

Comments
 (0)