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>2020-02-01 19:16:23 +0300
committerRich Trott <rtrott@gmail.com>2020-02-08 00:01:59 +0300
commita555be2e45b283a201de21350c0115680a7d4e7c (patch)
treec494be3c06a27acfc77b11ca4a0bb873fb331142 /src/node_messaging.h
parente2a3a87060af4c48b2551d20dfede33183b1931d (diff)
worker: improve MessagePort performance
Use a JS function as the single entry point for emitting `.onmessage()` calls, avoiding the overhead of manually constructing each message event object in C++. confidence improvement accuracy (*) (**) (***) worker/echo.js n=100000 sendsPerBroadcast=1 payload='object' workers=1 *** 16.34 % ±1.16% ±1.54% ±1.99% worker/echo.js n=100000 sendsPerBroadcast=1 payload='string' workers=1 *** 24.41 % ±1.50% ±1.99% ±2.58% worker/echo.js n=100000 sendsPerBroadcast=10 payload='object' workers=1 *** 26.66 % ±1.54% ±2.05% ±2.65% worker/echo.js n=100000 sendsPerBroadcast=10 payload='string' workers=1 *** 32.72 % ±1.60% ±2.11% ±2.73% worker/messageport.js n=1000000 payload='object' *** 40.28 % ±1.48% ±1.95% ±2.52% worker/messageport.js n=1000000 payload='string' *** 76.95 % ±2.19% ±2.90% ±3.75% Also fix handling exceptions returned from `MessagePort::New`. PR-URL: https://github.com/nodejs/node/pull/31605 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_messaging.h')
-rw-r--r--src/node_messaging.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/node_messaging.h b/src/node_messaging.h
index 6d2410a7248..d687e7549d5 100644
--- a/src/node_messaging.h
+++ b/src/node_messaging.h
@@ -131,12 +131,16 @@ class MessagePortData : public MemoryRetainer {
// the uv_async_t handle that is used to notify the current event loop of
// new incoming messages.
class MessagePort : public HandleWrap {
- public:
+ private:
// Create a new MessagePort. The `context` argument specifies the Context
// instance that is used for creating the values emitted from this port.
+ // This is called by MessagePort::New(), which is the public API used for
+ // creating MessagePort instances.
MessagePort(Environment* env,
v8::Local<v8::Context> context,
v8::Local<v8::Object> wrap);
+
+ public:
~MessagePort() override;
// Create a new message port instance, optionally over an existing
@@ -205,6 +209,7 @@ class MessagePort : public HandleWrap {
std::unique_ptr<MessagePortData> data_ = nullptr;
bool receiving_messages_ = false;
uv_async_t async_;
+ v8::Global<v8::Function> emit_message_fn_;
friend class MessagePortData;
};