Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1d6bd9

Browse filesBrowse files
mscdexFishrock123
authored andcommitted
stream: improve Readable.read() performance
read() performance is improved most by switching from an array to a linked list for storing buffered data. However, other changes that also contribute include: making some hot functions inlinable, faster read() argument checking, and misc code rearrangement to avoid unnecessary code execution. PR-URL: #7077 Reviewed-By: Calvin Metcalf <calvin.metcalf@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 3d69ad1 commit e1d6bd9
Copy full SHA for e1d6bd9

File tree

Expand file treeCollapse file tree

10 files changed

+420
-137
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

10 files changed

+420
-137
lines changed
Open diff view settings
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const v8 = require('v8');
5+
const Readable = require('stream').Readable;
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [100e1]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const b = new Buffer(32);
14+
const s = new Readable();
15+
function noop() {}
16+
s._read = noop;
17+
18+
// Force optimization before starting the benchmark
19+
s.push(b);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(s.read)');
22+
s.push(b);
23+
while (s.read(128));
24+
25+
bench.start();
26+
for (var k = 0; k < n; ++k) {
27+
for (var i = 0; i < 1e4; ++i)
28+
s.push(b);
29+
while (s.read(128));
30+
}
31+
bench.end(n);
32+
}
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const v8 = require('v8');
5+
const Readable = require('stream').Readable;
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [100e1]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const b = new Buffer(32);
14+
const s = new Readable();
15+
function noop() {}
16+
s._read = noop;
17+
18+
// Force optimization before starting the benchmark
19+
s.push(b);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(s.read)');
22+
s.push(b);
23+
while (s.read(106));
24+
25+
bench.start();
26+
for (var k = 0; k < n; ++k) {
27+
for (var i = 0; i < 1e4; ++i)
28+
s.push(b);
29+
while (s.read(106));
30+
}
31+
bench.end(n);
32+
}
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const v8 = require('v8');
5+
const Readable = require('stream').Readable;
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [200e1]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const b = new Buffer(32);
14+
const s = new Readable();
15+
function noop() {}
16+
s._read = noop;
17+
18+
// Force optimization before starting the benchmark
19+
s.push(b);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(s.push)');
22+
eval('%OptimizeFunctionOnNextCall(s.read)');
23+
s.push(b);
24+
while (s.read(32));
25+
26+
bench.start();
27+
for (var k = 0; k < n; ++k) {
28+
for (var i = 0; i < 1e4; ++i)
29+
s.push(b);
30+
while (s.read(32));
31+
}
32+
bench.end(n);
33+
}
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const v8 = require('v8');
5+
const Readable = require('stream').Readable;
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [50e2]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const b = new Buffer(32);
14+
const s = new Readable();
15+
function noop() {}
16+
s._read = noop;
17+
18+
// Force optimization before starting the benchmark
19+
s.push(b);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(s.read)');
22+
s.push(b);
23+
while (s.read());
24+
25+
bench.start();
26+
for (var k = 0; k < n; ++k) {
27+
for (var i = 0; i < 1e4; ++i)
28+
s.push(b);
29+
while (s.read());
30+
}
31+
bench.end(n);
32+
}
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const v8 = require('v8');
5+
const Readable = require('stream').Readable;
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [100e1]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const b = new Buffer(32);
14+
const s = new Readable();
15+
function noop() {}
16+
s._read = noop;
17+
18+
// Force optimization before starting the benchmark
19+
s.push(b);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(s.read)');
22+
s.push(b);
23+
while (s.read(12));
24+
25+
bench.start();
26+
for (var k = 0; k < n; ++k) {
27+
for (var i = 0; i < 1e4; ++i)
28+
s.push(b);
29+
while (s.read(12));
30+
}
31+
bench.end(n);
32+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.