-
Notifications
You must be signed in to change notification settings - Fork 30k
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
vm: lazily initialize primordials for vm contexts #31738
Conversation
Lazily initialize primordials when cross-context support for builtins is needed to fix the performance regression in context creation.
return InitializePrimordials(context); | ||
} | ||
|
||
bool InitializePrimordials(Local<Context> context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block contains only indentation change
src/api/environment.cc
Outdated
@@ -407,6 +407,7 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) { | |||
Local<Object> exports = Object::New(isolate); | |||
if (context->Global()->SetPrivate(context, key, exports).IsNothing()) | |||
return MaybeLocal<Object>(); | |||
InitializePrimordials(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only hit for vm contexts and main contexts created without snapshot support so there's no additional cost for the main context built with snapshot support
@@ -405,7 +405,8 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) { | |||
return handle_scope.Escape(existing_value.As<Object>()); | |||
|
|||
Local<Object> exports = Object::New(isolate); | |||
if (context->Global()->SetPrivate(context, key, exports).IsNothing()) | |||
if (context->Global()->SetPrivate(context, key, exports).IsNothing() || | |||
!InitializePrimordials(context)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, forgot to handle the return value of InitializePrimordials
in the initial commit, fixed.
🙂 |
Landed in e6c2277. Thanks! |
@joyeecheung if this should go to |
Lazily initialize primordials when cross-context support for builtins is needed to fix the performance regression in context creation. PR-URL: nodejs#31738 Fixes: nodejs#29842 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
Fixes: #29842
local benchmark results
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes