Add EXPERIMENTAL_FASTCALL
This commit is contained in:
parent
886de7ab3c
commit
ec86c1ce11
@ -4,21 +4,18 @@
|
||||
#include <v8.h>
|
||||
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 <node.h>
|
||||
|
||||
/* This is a very hot function ruined by illiteracy */
|
||||
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 */
|
||||
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 */
|
||||
return f->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct PerContextData {
|
||||
|
@ -22,6 +22,9 @@
|
||||
#include <vector>
|
||||
#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>
|
||||
using namespace v8;
|
||||
|
||||
@ -79,14 +82,17 @@ void uWS_us_listen_socket_close(const FunctionCallbackInfo<Value> &args) {
|
||||
|
||||
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 */
|
||||
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 */
|
||||
/* Settings this crashes Node.js while debugging with breakpoints */
|
||||
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Init the template objects, SSL and non-SSL, store it in per context data */
|
||||
PerContextData *perContextData = new PerContextData;
|
||||
|
@ -18,6 +18,13 @@
|
||||
module.exports = (() => {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user