Skip to content

vm: lazily initialize primordials for vm contexts - #31738

Closed
joyeecheung wants to merge 2 commits into
nodejs:masterfrom
joyeecheung:no-primordials-for-context
Closed

vm: lazily initialize primordials for vm contexts#31738
joyeecheung wants to merge 2 commits into
nodejs:masterfrom
joyeecheung:no-primordials-for-context

Conversation

@joyeecheung

Copy link
Copy Markdown
Member

Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.

Fixes: #29842

local benchmark results

 confidence improvement accuracy (*) (**) (***)
vm/create-context.js n=100 *** 485.26 % ±15.48% ±21.32% ±29.29%
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. vm Issues and PRs related to the vm subsystem. labels Feb 11, 2020
return InitializePrimordials(context);
}

bool InitializePrimordials(Local<Context> context) {

Copy link
Copy Markdown
MemberAuthor

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadsrc/api/environment.cc Outdated
Local<Object> exports = Object::New(isolate);
if (context->Global()->SetPrivate(context, key, exports).IsNothing())
return MaybeLocal<Object>();
InitializePrimordials(context);

@joyeecheungjoyeecheungFeb 11, 2020

Copy link
Copy Markdown
MemberAuthor

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

@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Local<Object> exports = Object::New(isolate);
if (context->Global()->SetPrivate(context, key, exports).IsNothing())
if (context->Global()->SetPrivate(context, key, exports).IsNothing() ||
!InitializePrimordials(context))

Copy link
Copy Markdown
MemberAuthor

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.

@addaleax

Copy link
Copy Markdown
Member
16:41:47 confidence improvement accuracy (*) (**) (***)
16:41:47 vm/create-context.js n=100 *** 371.94 % ±21.00% ±28.29% ±37.54%

🙂

@addaleaxaddaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 13, 2020
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

joyeecheung added a commit that referenced this pull request Feb 19, 2020
Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
PR-URL: #31738Fixes: #29842
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Landed in e6c2277. Thanks!

codebytere pushed a commit that referenced this pull request Feb 27, 2020
Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
PR-URL: #31738Fixes: #29842
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
@codebyterecodebytere mentioned this pull request Feb 29, 2020
@codebytere

Copy link
Copy Markdown
Member

@joyeecheung if this should go to v12.x can you please open a manual backport? There are some conflicts i'd rather not chance myself.

targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
PR-URL: nodejs#31738Fixes: nodejs#29842
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
targos pushed a commit that referenced this pull request Apr 28, 2020
Lazily initialize primordials when cross-context support for
builtins is needed to fix the performance regression in context
creation.
PR-URL: #31738Fixes: #29842
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
@targostargos mentioned this pull request May 2, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.vmIssues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Significant slowdown of createContext and runInContext

7 participants

@joyeecheung@nodejs-github-bot@addaleax@codebytere@devnexen@devsnek@targos