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

node_contextify tracking issue #6283

Closed
10 of 12 tasks
ofrobots opened this issue Apr 19, 2016 · 24 comments
Closed
10 of 12 tasks

node_contextify tracking issue #6283

ofrobots opened this issue Apr 19, 2016 · 24 comments
Assignees
Labels
vm Issues and PRs related to the vm subsystem.

Comments

@ofrobots
Copy link
Contributor

ofrobots commented Apr 19, 2016

The implementation of the vm module has some limitation that results in non-intuitive behaviour. There are already a few bugs open for this (see list below). At this point I do not think there are incremental fixes that can solve the issues with the vm module. I suspect that a revamp of the vm module might be needed, with some API help from the V8 team, to fix these issues properly.

Existing open issues:

I am creating this issue to make it easier to keep track of these issues, and possible solutions.

/cc @nodejs/v8 @domenic.

@ofrobots ofrobots added the vm Issues and PRs related to the vm subsystem. label Apr 19, 2016
fhinkel added a commit to fhinkel/node that referenced this issue Jul 22, 2016
A lot of contextify issues seem to be related to the fact that we
cannot intercept defineProperty(), see
nodejs#6283.

Here is a proof of concept implementation that gets rid of the
CopyProperties() hack in contextify. For simplicty, only getters from the
descriptors are copied. Also, function declarations are not intercepted,
but that should be easy to do.

It'll be a while until I get this cleanly into V8, but I think once the
V8 API allows for intercepting defineProperty() and function declarations,
a lot of contextify issues can be solved.
@fhinkel fhinkel self-assigned this Sep 7, 2016
@bmeck
Copy link
Member

bmeck commented Sep 29, 2016

The problem is API design that I can tell. We "enhance" and return the sandbox object passed in to vm.createContext() but the behavior of the v8::Context::Global() in v8 cannot delegate fully with behaviors back to the sandbox (like Object.defineProperty). We should really return a new Proxy from vm.createContext that can propagate into the VM Global(). This is a breaking change but this relates to most of this list.

@fhinkel
Copy link
Member

fhinkel commented Sep 29, 2016

We discussed the proxy idea in #7820.

We made API changes in V8. Fixing the issues here should be possible as soon as we pull in a newer V8 version.

@bmeck
Copy link
Member

bmeck commented Sep 29, 2016

@fhinkel that was describing a Proxy inside of the Context as the Global proxy, I was thinking of a Proxy outside of the v8::Context and using something like newRemoteContext. The use case described by @domenic to my knowledge was around needing to generate the Global() reference (that is ===) prior to creating a full context. Looking at the code as well, it seems that Node should be using FromSnapshot which it currently does not. If possible I would like to move away from interceptors if possible.

@dead-claudia
Copy link

dead-claudia commented Oct 3, 2016

BTW the box for #5344 should probably now be checked, since that issue is now closed.

@fhinkel
Copy link
Member

fhinkel commented Dec 11, 2016

#10223

@cpojer
Copy link

cpojer commented Dec 15, 2016

I'm really excited about improvements to vm context. Jest, the JavaScript testing framework, heavily uses the vm module to isolate tests. Is there any way we can make sure that Jest keeps working or that we are aware of potential breaking changes? Is it at all possible for you to include yarn test (or yarn test -i to run everything within a single process) inside of the Jest repo to the test plans for changes here? Jest is used for testing by a ton of companies, so it may make sense to ensure we don't break anything here and that we are aware of changes that are coming.

It may actually be a good real-world test for you, too. I'm happy to talk more about the architecture but in essence Jest parallelizes across worker processes and has a custom node-like (or jsdom) env in a vm context that also comes with a powerful custom require implementation that can be used for module-boundary mocking.

I also had thoughts around vm.Script. It has the cached data feature via the produceCachedData and cachedData fields. I had hopes that this would speed up repeated script execution which could be pretty significant for Jest but was surprised there was no performance benefit of using this at all across thousands of test files and tens of thousands of modules at FB. Besides the API of this feature, which is really odd, is there any way this feature can be changed to be more efficient? I kind of don't really get why v8 has to validate the cached data as that also requires to store both the original source and the cached data. This may be topic for a separate issue but I just wanted to bring it up.

Context:

@fhinkel
Copy link
Member

fhinkel commented Dec 15, 2016

Good idea to use Jest tests as test cases for vm changes. Anything we break, we can add as regression tests (and fix it of course). The vm module could certainly have a better test coverage.

@bnoordhuis recently ran some benchmarks with and without vm. Slowdown is pretty dramatic. Definitely worth looking into how to speed it up.

@bmeck
Copy link
Member

bmeck commented Dec 15, 2016

@cpojer in order to see speed gains vs the IO you need to implement a large cache store, doing it per file might actually slow things down. I can walk you through it sometime if you want.

@cpojer
Copy link

cpojer commented Dec 15, 2016

A large cache store of what? In the third link I shared above you can see how we share vm.Script instances during a single run; as long as the file doesn't change, so there isn't any IO involved.

@bmeck
Copy link
Member

bmeck commented Dec 15, 2016

@cpojer i see no call w/ produceCachedData and no file in which those results are stored in the source https://github.com/facebook/jest/search?utf8=%E2%9C%93&q=produceCachedData&type=Issues . Even if this is implemented the wrapper you show has a per file cache of the source transform, and it can be expensive to load in cache files off disk ad-hoc vs as a large bundle of cachedData. This is somewhat off topic and might be better done offline.

@cjihrig
Copy link
Contributor

cjihrig commented Dec 16, 2016

@thealphanerd perhaps we should add jest to CITGM. Looks like it was mentioned in nodejs/citgm#127.

@MylesBorins
Copy link
Contributor

I've pinged someone to put together a PR of the various testing frameworks.

@fhinkel
Copy link
Member

fhinkel commented Feb 5, 2017

67af1ad replaces call into JS in CopyProperties() with correct API call.

@fhinkel
Copy link
Member

fhinkel commented Feb 13, 2017

@cpojer I'm running npm test in Jest after making changes to Node core. Anything else I can run to make sure my vm fixes don't break anything in Jest?

@targos
Copy link
Member

targos commented Feb 13, 2017

@fhinkel I suppose it would be useful to run jsdom tests too.

@fhinkel
Copy link
Member

fhinkel commented Feb 13, 2017

I can't get them to pass even without my changes 😞

@domenic
Copy link
Contributor

domenic commented Feb 13, 2017

@fhinkel feel free to open an issue with the failures

@cpojer
Copy link

cpojer commented Feb 13, 2017

@fhinkel yes, unless you are significantly changing behavior, running "npm test" on Jest's repo should work. Thank you so much for reaching out!

@fhinkel
Copy link
Member

fhinkel commented Feb 13, 2017

I didn't configure the web platform tests, so it's probably my fault. But I get the same failures with and without my changes, I'll take that as no regression.

@AnnaMag
Copy link
Member

AnnaMag commented Jun 3, 2017

Progress update: solution to the issues occurring due to the CP() hack is ready, pending another pair of eyes willing to review the code + V8 changes to be approved and land 😄
#13265

@bmeck bmeck mentioned this issue Sep 15, 2017
2 tasks
fhinkel added a commit to fhinkel/node that referenced this issue Oct 23, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

Refs: nodejs#6283
Refs: nodejs#15114
Refs: nodejs#13265

Fixes: nodejs#2734
Fixes: nodejs#10223
Fixes: nodejs#11803
Fixes: nodejs#11902
fhinkel added a commit to fhinkel/node that referenced this issue Oct 23, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

PR-URL: nodejs#16293
Fixes: nodejs#2734
Fixes: nodejs#10223
Fixes: nodejs#11803
Fixes: nodejs#11902
Ref: nodejs#6283
Ref: nodejs#15114
Ref: nodejs#13265
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@fhinkel
Copy link
Member

fhinkel commented Oct 23, 2017

@ofrobots The remaining 4 issues are not related. Should we close this tracking issue?

addaleax pushed a commit to ayojs/ayo that referenced this issue Oct 26, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs/node#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs/node#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

PR-URL: nodejs/node#16293
Fixes: nodejs/node#2734
Fixes: nodejs/node#10223
Fixes: nodejs/node#11803
Fixes: nodejs/node#11902
Ref: nodejs/node#6283
Ref: nodejs/node#15114
Ref: nodejs/node#13265
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@ofrobots
Copy link
Contributor Author

Agree. Closing.

addaleax pushed a commit to ayojs/ayo that referenced this issue Dec 7, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs/node#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs/node#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

PR-URL: nodejs/node#16293
Fixes: nodejs/node#2734
Fixes: nodejs/node#10223
Fixes: nodejs/node#11803
Fixes: nodejs/node#11902
Ref: nodejs/node#6283
Ref: nodejs/node#15114
Ref: nodejs/node#13265
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

11 participants