Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-10-23 09:23:02 +0300
committerMichaƫl Zasso <targos@protonmail.com>2018-10-28 17:15:15 +0300
commitf01518edfd83e2235d84485d87621e61f675b4a7 (patch)
tree20a562e8e3d86cce4787fef5847baaced6015a53 /src/stream_base.cc
parent0a23538e49e27b95ee35b051b6507eca74e2bb20 (diff)
src: improve StreamBase write throughput
Improve performance by transferring information about write status to JS through an `AliasedBuffer`, rather than object properties set from C++. PR-URL: https://github.com/nodejs/node/pull/23843 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r--src/stream_base.cc33
1 files changed, 7 insertions, 26 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc
index 57713d5eaf3..adb839c3e5d 100644
--- a/src/stream_base.cc
+++ b/src/stream_base.cc
@@ -18,13 +18,11 @@ namespace node {
using v8::Array;
using v8::ArrayBuffer;
-using v8::Boolean;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Integer;
using v8::Local;
-using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
@@ -56,18 +54,9 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
return Shutdown(req_wrap_obj);
}
-inline void SetWriteResultPropertiesOnWrapObject(
- Environment* env,
- Local<Object> req_wrap_obj,
- const StreamWriteResult& res) {
- req_wrap_obj->Set(
- env->context(),
- env->bytes_string(),
- Number::New(env->isolate(), res.bytes)).FromJust();
- req_wrap_obj->Set(
- env->context(),
- env->async(),
- Boolean::New(env->isolate(), res.async)).FromJust();
+void StreamBase::SetWriteResult(const StreamWriteResult& res) {
+ env_->stream_base_state()[kBytesWritten] = res.bytes;
+ env_->stream_base_state()[kLastWriteWasAsync] = res.async;
}
int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
@@ -160,7 +149,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
}
StreamWriteResult res = Write(*bufs, count, nullptr, req_wrap_obj);
- SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res);
+ SetWriteResult(res);
if (res.wrap != nullptr && storage_size > 0) {
res.wrap->SetAllocatedStorage(storage.release(), storage_size);
}
@@ -185,10 +174,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
buf.len = Buffer::Length(args[1]);
StreamWriteResult res = Write(&buf, 1, nullptr, req_wrap_obj);
-
- if (res.async)
- req_wrap_obj->Set(env->context(), env->buffer_string(), args[1]).FromJust();
- SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res);
+ SetWriteResult(res);
return res.err;
}
@@ -247,12 +233,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
// Immediate failure or success
if (err != 0 || count == 0) {
- req_wrap_obj->Set(env->context(), env->async(), False(env->isolate()))
- .FromJust();
- req_wrap_obj->Set(env->context(),
- env->bytes_string(),
- Integer::NewFromUnsigned(env->isolate(), data_size))
- .FromJust();
+ SetWriteResult(StreamWriteResult { false, err, nullptr, data_size });
return err;
}
@@ -295,7 +276,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj);
res.bytes += synchronously_written;
- SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res);
+ SetWriteResult(res);
if (res.wrap != nullptr) {
res.wrap->SetAllocatedStorage(data.release(), data_size);
}