Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: js fast path for cached bindings #18365

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
process: move moduleLoadList definition & usage to JS
  • Loading branch information
apapirovski committed Jan 25, 2018
commit ea60d2c198738a0762a34fbb51021e0e1715bc5f
18 changes: 15 additions & 3 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,25 @@
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}

const moduleLoadList = [];
Object.defineProperty(process, 'moduleLoadList', {
value: moduleLoadList,
configurable: true,
enumerable: true,
writable: false
});

{
const bindingObj = Object.create(null);

const getBinding = process.binding;
process.binding = function binding(module) {
module = String(module);
let mod = bindingObj[module];
if (typeof mod !== 'object')
if (typeof mod !== 'object') {
mod = bindingObj[module] = getBinding(module);
moduleLoadList.push(`Binding ${module}`);
}
return mod;
};

Expand All @@ -273,8 +283,10 @@

internalBinding = function internalBinding(module) {
let mod = bindingObj[module];
if (typeof mod !== 'object')
if (typeof mod !== 'object') {
mod = bindingObj[module] = getInternalBinding(module);
moduleLoadList.push(`Internal Binding ${module}`);
}
return mod;
};
}
Expand Down Expand Up @@ -583,7 +595,7 @@
throw err;
}

process.moduleLoadList.push(`NativeModule ${id}`);
moduleLoadList.push(`NativeModule ${id}`);

const nativeModule = new NativeModule(id);

Expand Down
2 changes: 0 additions & 2 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ inline Environment::Environment(IsolateData* isolate_data,
v8::Context::Scope context_scope(context);
set_as_external(v8::External::New(isolate(), this));

set_module_load_list_array(v8::Array::New(isolate()));

AssignToContext(context, ContextInfo(""));

destroy_async_id_list_.reserve(512);
Expand Down
1 change: 0 additions & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ class ModuleWrap;
V(http2settings_constructor_template, v8::ObjectTemplate) \
V(immediate_callback_function, v8::Function) \
V(inspector_console_api_object, v8::Object) \
V(module_load_list_array, v8::Array) \
V(pbkdf2_constructor_template, v8::ObjectTemplate) \
V(pipe_constructor_template, v8::FunctionTemplate) \
V(performance_entry_callback, v8::Function) \
Expand Down
21 changes: 0 additions & 21 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2556,15 +2556,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString());

Local<String> module = args[0].As<String>();

// Append a string to process.moduleLoadList
char buf[1024];
node::Utf8Value module_v(env->isolate(), module);
snprintf(buf, sizeof(buf), "Binding %s", *module_v);

Local<Array> modules = env->module_load_list_array();
uint32_t l = modules->Length();
modules->Set(l, OneByteString(env->isolate(), buf));

node_module* mod = get_builtin_module(*module_v);
Local<Object> exports;
Expand All @@ -2591,15 +2583,7 @@ static void InternalBinding(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString());

Local<String> module = args[0].As<String>();

// Append a string to process.moduleLoadList
char buf[1024];
node::Utf8Value module_v(env->isolate(), module);
snprintf(buf, sizeof(buf), "Internal Binding %s", *module_v);

Local<Array> modules = env->module_load_list_array();
uint32_t l = modules->Length();
modules->Set(l, OneByteString(env->isolate(), buf));

node_module* mod = get_internal_module(*module_v);
if (mod == nullptr) return ThrowIfNoSuchModule(env, *module_v);
Expand Down Expand Up @@ -2971,11 +2955,6 @@ void SetupProcessObject(Environment* env,
"version",
FIXED_ONE_BYTE_STRING(env->isolate(), NODE_VERSION));

// process.moduleLoadList
READONLY_PROPERTY(process,
"moduleLoadList",
env->module_load_list_array());

// process.versions
Local<Object> versions = Object::New(env->isolate());
READONLY_PROPERTY(process, "versions", versions);
Expand Down