summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-10-21 08:34:00 +0200
committerAnna Henningsen <anna@addaleax.net>2018-10-24 09:57:42 +0200
commit1365f657b51d31044cca54c3152d3940a4bd9dc3 (patch)
tree4772c2b484555de0a0368b35ebf889ff23d154c2 /test
parentbb79e768e5ab150f2075780734005783d53eb3ca (diff)
downloadandroid-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.tar.gz
android-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.tar.bz2
android-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.zip
src: improve StreamBase read throughput
Improve performance by providing JS with the raw ingridients for the read data, i.e. an `ArrayBuffer` + offset + length fields, instead of creating `Buffer` instances in C++ land. PR-URL: https://github.com/nodejs/node/pull/23797 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-net-end-close.js6
-rw-r--r--test/parallel/test-process-wrap.js5
-rw-r--r--test/parallel/test-tcp-wrap-listen.js14
3 files changed, 18 insertions, 7 deletions
diff --git a/test/parallel/test-net-end-close.js b/test/parallel/test-net-end-close.js
index c0705da9d0..b488f16510 100644
--- a/test/parallel/test-net-end-close.js
+++ b/test/parallel/test-net-end-close.js
@@ -6,11 +6,15 @@ const net = require('net');
const { internalBinding } = require('internal/test/binding');
const { UV_EOF } = internalBinding('uv');
+const { streamBaseState, kReadBytesOrError } = internalBinding('stream_wrap');
const s = new net.Socket({
handle: {
readStart: function() {
- setImmediate(() => this.onread(UV_EOF, null));
+ setImmediate(() => {
+ streamBaseState[kReadBytesOrError] = UV_EOF;
+ this.onread();
+ });
},
close: (cb) => setImmediate(cb)
},
diff --git a/test/parallel/test-process-wrap.js b/test/parallel/test-process-wrap.js
index eccdeb5d07..ef9075e915 100644
--- a/test/parallel/test-process-wrap.js
+++ b/test/parallel/test-process-wrap.js
@@ -44,11 +44,10 @@ p.onexit = function(exitCode, signal) {
processExited = true;
};
-pipe.onread = function(err, b, off, len) {
+pipe.onread = function(arrayBuffer) {
assert.ok(processExited);
- if (b) {
+ if (arrayBuffer) {
gotPipeData = true;
- console.log('read %d', len);
} else {
gotPipeEOF = true;
pipe.close();
diff --git a/test/parallel/test-tcp-wrap-listen.js b/test/parallel/test-tcp-wrap-listen.js
index 9ecdf60f8c..72981b683c 100644
--- a/test/parallel/test-tcp-wrap-listen.js
+++ b/test/parallel/test-tcp-wrap-listen.js
@@ -5,7 +5,12 @@ const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
-const { WriteWrap } = internalBinding('stream_wrap');
+const {
+ WriteWrap,
+ kReadBytesOrError,
+ kArrayBufferOffset,
+ streamBaseState
+} = internalBinding('stream_wrap');
const server = new TCP(TCPConstants.SOCKET);
@@ -30,8 +35,11 @@ server.onconnection = (err, client) => {
client.readStart();
client.pendingWrites = [];
- client.onread = common.mustCall((err, buffer) => {
- if (buffer) {
+ client.onread = common.mustCall((arrayBuffer) => {
+ if (arrayBuffer) {
+ const offset = streamBaseState[kArrayBufferOffset];
+ const nread = streamBaseState[kReadBytesOrError];
+ const buffer = Buffer.from(arrayBuffer, offset, nread);
assert.ok(buffer.length > 0);
assert.strictEqual(client.writeQueueSize, 0);