GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vm: include vm context in the embedded snapshot by joyeecheung · Pull Request #44252 · nodejs/node

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Aug 16, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The first commit comes from #44258

vm: make ContextifyContext template context-independent

Instead of creating an object template for every ContextifyContext,
we now create one object template that can be reused by all
contexts. The native pointer can be obtained through an embdder
pointer field in the creation context of the receiver in the
interceptors, because the interceptors are only meant to be invoked
on the global object of the contextified contexts. This makes
the ContextifyContext template context-independent and therefore
snapshotable.

vm: include vm context in the embedded snapshot

Include a minimally initialized contextify context in the embedded
snapshot. This paves the way for user-land vm context snapshots.

vm: avoid unnecessary property getter interceptor calls

Access to the global object from within a vm context is intercepted
so it's slow, therefore we should try to avoid unnecessary access
to it during the initialization of vm contexts.

  • Remove the Atomics.wake deletion as V8 now does not install it
    anymore.
  • Move the Intl.v8BreakIterator deletion into the snapshot.
  • Do not query the Object prototype if --disable-proto is not set.

This should speed up the creation of vm contexts by about ~12%.

Refs: #44014
Refs: #37476

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

goloveychuk, bricss, and c0sx reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@nodejs-github-bot

nodejs-github-bot commented Aug 16, 2022

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Aug 16, 2022
@joyeecheung
joyeecheung force-pushed the snapshot-context branch from 29c650e to e582c5c Compare August 16, 2022 17:17
joyeecheung
joyeecheung commented Aug 16, 2022
View reviewed changes
Comment thread src/node_contextify.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mscdex

mscdex commented Aug 16, 2022

Copy link
Copy Markdown
Contributor

s/embeded/embedded in commit message

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

legendecas
legendecas reviewed Aug 17, 2022
View reviewed changes
Comment thread src/node_contextify.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/node_contextify.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/node_contextify.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@legendecas legendecas mentioned this pull request Aug 17, 2022
src: extract common context embedder tag checks #44258
Closed
@joyeecheung
joyeecheung force-pushed the snapshot-context branch 2 times, most recently from c32efba to 5e2a212 Compare August 17, 2022 10:25
@joyeecheung

joyeecheung commented Aug 17, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Rebased on top of #44258 and added a commit that makes use of the snapshot to speed up the initialization of the vm contexts a bit.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Aug 17, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/46050/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Aug 17, 2022

Copy link
Copy Markdown
Member Author

From the CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1174

20:50:54                                                                       confidence improvement accuracy (*)    (**)   (***)
20:50:55 vm/create-context.js n=1000                                                  ***      7.34 %       ±2.99%  ±3.97%  ±5.17%
20:50:55 vm/run-in-context.js withSigintListener=0 breakOnSigint=0 n=1000                     -6.14 %       ±6.57%  ±8.75% ±11.40%
20:50:55 vm/run-in-context.js withSigintListener=0 breakOnSigint=1 n=1000                      1.28 %      ±12.90% ±17.18% ±22.38%
20:50:55 vm/run-in-context.js withSigintListener=1 breakOnSigint=0 n=1000                     -6.66 %       ±8.39% ±11.16% ±14.53%
20:50:55 vm/run-in-context.js withSigintListener=1 breakOnSigint=1 n=1000                     -1.86 %      ±11.60% ±15.44% ±20.10%
20:50:55 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=0 n=1000                -0.87 %       ±7.80% ±10.38% ±13.52%
20:50:55 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=1 n=1000                 3.06 %      ±22.00% ±29.27% ±38.10%
20:50:55 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=0 n=1000                -1.53 %       ±9.74% ±12.96% ±16.87%
20:50:55 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=1 n=1000                -0.26 %      ±12.00% ±15.97% ±20.79%

It seems that I needed to bump up the number of iterations (--set n=1000) to get a stable number from the benchmarks though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex mscdex changed the title vm: include vm context in the embeded snapshot vm: include vm context in the embedded snapshot Aug 17, 2022
@joyeecheung joyeecheung added review wanted PRs that need review. vm Issues and PRs related to the vm subsystem. labels Aug 18, 2022
@goloveychuk

goloveychuk commented Aug 18, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

I've found that (inside build snapshot)

const vm = require('vm')

const context = vm.createContext();
console.log(context, vm.isContext(context))
const global2 = vm.runInContext(
    'this',
    context,
)

throws an error

TypeError: The "contextifiedObject" argument must be an vm.Context. Received an instance of Object

should it be fixed in this PR or next?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Aug 18, 2022

Copy link
Copy Markdown
Member Author

@goloveychuk My plan is to implement user-land vm context it in another PR (because that requires more refactoring to the lifetime management of the bindings), this only adds support for vm context in the embedded snapshot, which isn't that complex.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@goloveychuk

This comment was marked as off-topic.

Sign in to view
@joyeecheung joyeecheung added the blocked PRs that are blocked by other issues or PRs. label Aug 18, 2022
@joyeecheung

This comment was marked as off-topic.

Sign in to view
@goloveychuk

This comment was marked as off-topic.

Sign in to view
@joyeecheung

This comment was marked as off-topic.

Sign in to view
@joyeecheung joyeecheung mentioned this pull request Aug 18, 2022
Support for user-land modules in the user-land snapshots #44277
Closed
@joyeecheung

joyeecheung commented Aug 18, 2022

Copy link
Copy Markdown
Member Author

Opened #44277 and transferred the discussions there, in case this PR goes too off-topic. @goloveychuk please use that thread for discussions about user-land modules instead, thanks

goloveychuk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

legendecas added a commit that referenced this pull request Aug 19, 2022
@legendecas
src: extract common context embedder tag checks
5e57d24
Extract common context embedder tag checks to ContextEmbedderTag so
that verifying if a context is a node context doesn't need to access
private members of node::Environment.

PR-URL: #44258
Refs: #44179
Refs: #44252
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
joyeecheung added 3 commits August 19, 2022 14:50
@joyeecheung
vm: make ContextifyContext template context-independent
c0f1430
Instead of creating an object template for every ContextifyContext,
we now create one object template that can be reused by all
contexts. The native pointer can be obtained through an embdder
pointer field in the creation context of the receiver in the
interceptors, because the interceptors are only meant to be invoked
on the global object of the contextified contexts. This makes
the ContextifyContext template context-independent and therefore
snapshotable.
@joyeecheung
vm: include vm context in the embedded snapshot
f60d687
Include a minimally initialized contextify context in the embedded
snapshot. This paves the way for user-land vm context snapshots.
@joyeecheung
vm: avoid unnecessary property getter interceptor calls
c507be8
Access to the global object from within a vm context is intercepted
so it's slow, therefore we should try to avoid unnecessary access
to it during the initialization of vm contexts.

- Remove the Atomics.wake deletion as V8 now does not install it
  anymore.
- Move the Intl.v8BreakIterator deletion into the snapshot.
- Do not query the Object prototype if --disable-proto is not set.

This should speed up the creation of vm contexts by about ~12%.
@RafaelGSS RafaelGSS mentioned this pull request Sep 5, 2022
v18.9.0 release proposal #44521
Merged
RafaelGSS added a commit that referenced this pull request Sep 5, 2022
@RafaelGSS
2022-09-05, Version v18.9.0 (Current)
57f2493
Notable changes:

* cli:
  * (SEMVER-MINOR) add `--watch` (Moshe Atlow) #44366
* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) #44355
* lib:
  * (SEMVER-MINOR) add diagnostics channel for process and worker (theanarkh) #44045
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) #44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) #44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) #44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) #44252

PR-URL: #44521
RafaelGSS added a commit that referenced this pull request Sep 6, 2022
@RafaelGSS
2022-09-07, Version v18.9.0 (Current)
1b6b325
Notable changes:

* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) #44355
* lib:
  * (SEMVER-MINOR) add diagnostics channel for process and worker (theanarkh) #44045
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) #44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) #44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) #44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) #44252

PR-URL: #44521
RafaelGSS added a commit that referenced this pull request Sep 6, 2022
@RafaelGSS
2022-09-07, Version v18.9.0 (Current)
919631e
Notable changes:

* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) #44355
* lib:
  * (SEMVER-MINOR) add diagnostics channel for process and worker (theanarkh) #44045
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) #44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) #44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) #44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) #44252

PR-URL: #44521
RafaelGSS added a commit to RafaelGSS/node that referenced this pull request Sep 7, 2022
@RafaelGSS
2022-09-07, Version v18.9.0 (Current)
9bfdc87
Notable changes:

* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) nodejs#44355
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) nodejs#44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) nodejs#44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) nodejs#44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) nodejs#44252

PR-URL: nodejs#44521
RafaelGSS added a commit that referenced this pull request Sep 7, 2022
@RafaelGSS
2022-09-08, Version v18.9.0 (Current)
9ae2af4
Notable changes:

* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) #44355
* lib:
  * (SEMVER-MINOR) add diagnostics channel for process and worker (theanarkh) #44045
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) #44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) #44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) #44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) #44252

PR-URL: #44521
RafaelGSS added a commit that referenced this pull request Sep 8, 2022
@RafaelGSS
2022-09-08, Version v18.9.0 (Current)
fd277b2
Notable changes:

* doc:
  * add daeyeon to collaborators (Daeyeon Jeong) #44355
* lib:
  * (SEMVER-MINOR) add diagnostics channel for process and worker (theanarkh) #44045
* os:
  * (SEMVER-MINOR) add machine method (theanarkh) #44416
* report:
  * (SEMVER-MINOR) expose report public native apis (Chengzhong Wu) #44255
* src:
  * (SEMVER-MINOR) expose environment RequestInterrupt api (Chengzhong Wu) #44362
* vm:
  * include vm context in the embedded snapshot (Joyee Cheung) #44252

PR-URL: #44521
@juanarbol juanarbol added the backport-requested-v16.x label Oct 3, 2022
@juanarbol

juanarbol commented Oct 3, 2022

Copy link
Copy Markdown
Member

This is not landing cleanly in v16.x

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

juanarbol pushed a commit that referenced this pull request Oct 11, 2022
@legendecas @juanarbol
src: extract common context embedder tag checks
b186684
Extract common context embedder tag checks to ContextEmbedderTag so
that verifying if a context is a node context doesn't need to access
private members of node::Environment.

PR-URL: #44258
Refs: #44179
Refs: #44252
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
@joyeecheung joyeecheung mentioned this pull request Nov 30, 2022
bootstrap: lazy load non-essential modules #45659
Merged
guangwong pushed a commit to noslate-project/node that referenced this pull request Jan 3, 2023
@legendecas @guangwong
src: extract common context embedder tag checks
48ae163
Extract common context embedder tag checks to ContextEmbedderTag so
that verifying if a context is a node context doesn't need to access
private members of node::Environment.

PR-URL: nodejs/node#44258
Refs: nodejs/node#44179
Refs: nodejs/node#44252
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
guangwong pushed a commit to noslate-project/node that referenced this pull request Jan 3, 2023
@legendecas @guangwong
src: extract common context embedder tag checks
e36602f
Extract common context embedder tag checks to ContextEmbedderTag so
that verifying if a context is a node context doesn't need to access
private members of node::Environment.

PR-URL: nodejs/node#44258
Refs: nodejs/node#44179
Refs: nodejs/node#44252
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
@codebytere codebytere mentioned this pull request Mar 6, 2023
fix: crash when using vm after window.open() electron/electron#37506
Closed
3 of 4 tasks
@legendecas legendecas mentioned this pull request Aug 23, 2024
vm: return all own names and symbols in property enumerator #54522
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@legendecas legendecas legendecas approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. review wanted PRs that need review. vm Issues and PRs related to the vm subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@joyeecheung @nodejs-github-bot @mscdex @goloveychuk @juanarbol @legendecas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.