From ec86c1ce115d574fb3157ca33a8891d140f0338b Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 23 Feb 2020 16:19:58 +0100 Subject: [PATCH] Add EXPERIMENTAL_FASTCALL --- src/Utilities.h | 11 ++++------- src/addon.cpp | 18 ++++++++++++------ src/uws.js | 7 +++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Utilities.h b/src/Utilities.h index a81b46d..999712c 100644 --- a/src/Utilities.h +++ b/src/Utilities.h @@ -4,21 +4,18 @@ #include using namespace v8; -/* Unfortunately we have to perform like garbage to be friends with Node.js */ -#define PERFORM_LIKE_GARBAGE - /* Unfortunately we have to depend on Node.js garbage */ #include /* This is a very hot function ruined by illiteracy */ MaybeLocal CallJS(Isolate *isolate, Local f, int argc, Local *argv) { - #ifdef PERFORM_LIKE_GARBAGE + if (!experimental_fastcall) { /* Node.js is built by incompetent people who should never have touched a computer in the first place */ - return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0}); - #else + return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0}); + } else { /* Google LLC don't hire incompetent people to work on their stuff */ return f->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), argc, argv); - #endif + } } struct PerContextData { diff --git a/src/addon.cpp b/src/addon.cpp index 22a7218..8b8f28c 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -22,6 +22,9 @@ #include #include +/* This one can never change for the duration of this process, so never mind per context data:ing it, yes that is a word now */ +bool experimental_fastcall = 0; + #include using namespace v8; @@ -79,14 +82,17 @@ void uWS_us_listen_socket_close(const FunctionCallbackInfo &args) { void Main(Local exports) { + /* We only care if it is defined, not what it says */ + experimental_fastcall = getenv("EXPERIMENTAL_FASTCALL") != nullptr; + /* We pass isolate everywhere */ Isolate *isolate = exports->GetIsolate(); -#ifndef PERFORM_LIKE_GARBAGE - /* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */ - /* Settings this crashes Node.js while debugging with breakpoints */ - isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto); -#endif + if (experimental_fastcall) { + /* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */ + /* Settings this crashes Node.js while debugging with breakpoints */ + isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto); + } /* Init the template objects, SSL and non-SSL, store it in per context data */ PerContextData *perContextData = new PerContextData; @@ -127,4 +133,4 @@ NODE_MODULE_INITIALIZER(Local exports, Local module, Local { try { const uWS = require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node'); + if (process.env.EXPERIMENTAL_FASTCALL) { + process.nextTick = (f, ...args) => { + Promise.resolve().then(() => { + f(...args); + }); + }; + } process.on('exit', uWS.free); return uWS; } catch (e) {