Add EXPERIMENTAL_FASTCALL

This commit is contained in:
Alex Hultman 2020-02-23 16:19:58 +01:00
parent 886de7ab3c
commit ec86c1ce11
3 changed files with 23 additions and 13 deletions

View File

@ -4,21 +4,18 @@
#include <v8.h> #include <v8.h>
using namespace v8; 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 */ /* Unfortunately we have to depend on Node.js garbage */
#include <node.h> #include <node.h>
/* This is a very hot function ruined by illiteracy */ /* This is a very hot function ruined by illiteracy */
MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Value> *argv) { MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Value> *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 */ /* 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}); return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0});
#else } else {
/* Google LLC don't hire incompetent people to work on their stuff */ /* Google LLC don't hire incompetent people to work on their stuff */
return f->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), argc, argv); return f->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), argc, argv);
#endif }
} }
struct PerContextData { struct PerContextData {

View File

@ -22,6 +22,9 @@
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
/* 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 <v8.h> #include <v8.h>
using namespace v8; using namespace v8;
@ -79,14 +82,17 @@ void uWS_us_listen_socket_close(const FunctionCallbackInfo<Value> &args) {
void Main(Local<Object> exports) { void Main(Local<Object> exports) {
/* We only care if it is defined, not what it says */
experimental_fastcall = getenv("EXPERIMENTAL_FASTCALL") != nullptr;
/* We pass isolate everywhere */ /* We pass isolate everywhere */
Isolate *isolate = exports->GetIsolate(); Isolate *isolate = exports->GetIsolate();
#ifndef PERFORM_LIKE_GARBAGE if (experimental_fastcall) {
/* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */ /* 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 */ /* Settings this crashes Node.js while debugging with breakpoints */
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto); isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto);
#endif }
/* Init the template objects, SSL and non-SSL, store it in per context data */ /* Init the template objects, SSL and non-SSL, store it in per context data */
PerContextData *perContextData = new PerContextData; PerContextData *perContextData = new PerContextData;
@ -127,4 +133,4 @@ NODE_MODULE_INITIALIZER(Local<Object> exports, Local<Value> module, Local<Contex
/* Register vanilla V8 addon */ /* Register vanilla V8 addon */
Main(exports); Main(exports);
} }
#endif #endif

View File

@ -18,6 +18,13 @@
module.exports = (() => { module.exports = (() => {
try { try {
const uWS = require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node'); 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); process.on('exit', uWS.free);
return uWS; return uWS;
} catch (e) { } catch (e) {