Skip to content

Commit b0f6789

Browse files
committed
stream: Remove bufferSize option
Now that highWaterMark increases when there are large reads, this greatly reduces the number of calls necessary to _read(size), assuming that _read actually respects the size argument.
1 parent d5a0940 commit b0f6789

File tree

7 files changed

+10
-24
lines changed

7 files changed

+10
-24
lines changed

doc/api/stream.markdown

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ method. (See below.)
9090
### new stream.Readable([options])
9191

9292
* `options` {Object}
93-
* `bufferSize` {Number} The size of the chunks to consume from the
94-
underlying resource. Default=16kb
9593
* `highWaterMark` {Number} The maximum number of bytes to store in
9694
the internal buffer before ceasing to read from the underlying
9795
resource. Default=16kb

lib/_stream_readable.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ util.inherits(Readable, Stream);
3232
function ReadableState(options, stream) {
3333
options = options || {};
3434

35-
// the argument passed to this._read(n)
36-
this.bufferSize = options.bufferSize || 16 * 1024;
37-
3835
// the point at which it stops calling _read() to fill the buffer
3936
// Note: 0 is a valid value, means "don't call _read preemptively ever"
4037
var hwm = options.highWaterMark;
4138
this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
4239

4340
// cast to ints.
44-
this.bufferSize = ~~this.bufferSize;
4541
this.highWaterMark = ~~this.highWaterMark;
4642

4743
this.buffer = [];
@@ -265,7 +261,7 @@ Readable.prototype.read = function(n) {
265261
if (state.length === 0)
266262
state.needReadable = true;
267263
// call internal read method
268-
this._read(state.bufferSize);
264+
this._read(state.highWaterMark);
269265
state.sync = false;
270266
}
271267

lib/_stream_transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function afterTransform(stream, er, data) {
102102

103103
var rs = stream._readableState;
104104
if (rs.needReadable || rs.length < rs.highWaterMark) {
105-
stream._read(rs.bufferSize);
105+
stream._read(rs.highWaterMark);
106106
}
107107
}
108108

@@ -165,7 +165,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
165165
if (ts.needTransform ||
166166
rs.needReadable ||
167167
rs.length < rs.highWaterMark)
168-
this._read(rs.bufferSize);
168+
this._read(rs.highWaterMark);
169169
}
170170
};
171171

lib/fs.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,6 @@ function ReadStream(path, options) {
14311431

14321432
// a little bit bigger buffer and water marks by default
14331433
options = util._extend({
1434-
bufferSize: 64 * 1024,
14351434
highWaterMark: 64 * 1024
14361435
}, options || {});
14371436

@@ -1505,10 +1504,9 @@ ReadStream.prototype._read = function(n) {
15051504
return;
15061505

15071506
if (!pool || pool.length - pool.used < kMinPoolSpace) {
1508-
// discard the old pool. Can't add to the free list because
1509-
// users might have refernces to slices on it.
1507+
// discard the old pool.
15101508
pool = null;
1511-
allocNewPool(this._readableState.bufferSize);
1509+
allocNewPool(this._readableState.highWaterMark);
15121510
}
15131511

15141512
// Grab another reference to the pool in the case that while we're

test/simple/test-stream-readable-flow-recursion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var Readable = require('stream').Readable;
3232
// throw an error if we trigger a nextTick warning.
3333
process.throwDeprecation = true;
3434

35-
var stream = new Readable({ highWaterMark: 2, bufferSize: 2 });
35+
var stream = new Readable({ highWaterMark: 2 });
3636
var reads = 0;
3737
stream._read = function(size) {
3838
reads++;
@@ -59,7 +59,7 @@ flow(stream, 5000, function() {
5959
});
6060

6161
process.on('exit', function(code) {
62-
assert.equal(reads, 5000);
62+
assert.equal(reads, 2);
6363
// we pushed up the high water mark
6464
assert.equal(stream._readableState.highWaterMark, 5000);
6565
assert.equal(stream._readableState.length, 5000);

test/simple/test-stream2-fs.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ var file = path.resolve(common.fixturesDir, 'x1024.txt');
3232

3333
var size = fs.statSync(file).size;
3434

35-
// expect to see chunks no more than 10 bytes each.
36-
var expectLengths = [];
37-
for (var i = size; i > 0; i -= 10) {
38-
expectLengths.push(Math.min(i, 10));
39-
}
35+
var expectLengths = [1024];
4036

4137
var util = require('util');
4238
var Stream = require('stream');
@@ -60,7 +56,7 @@ TestWriter.prototype.end = function(c) {
6056
this.emit('results', this.buffer);
6157
}
6258

63-
var r = new FSReadable(file, { bufferSize: 10 });
59+
var r = new FSReadable(file);
6460
var w = new TestWriter();
6561

6662
w.on('results', function(res) {

test/simple/test-stream2-set-encoding.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ process.nextTick(run);
6464
util.inherits(TestReader, R);
6565

6666
function TestReader(n, opts) {
67-
R.call(this, util._extend({
68-
bufferSize: 5
69-
}, opts));
67+
R.call(this, opts);
7068

7169
this.pos = 0;
7270
this.len = n || 100;

0 commit comments

Comments
 (0)