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

module: expose Module._runInThisContext #6288

Closed

Conversation

indutny
Copy link
Member

@indutny indutny commented Apr 19, 2016

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Affected core subsystem(s)

module

Description of change

Module._runInThisContext can be overridden to store/load cached
compilation artifacts when embedding node.js .

cc @nodejs/collaborators @zcbenz

`Module._runInThisContext` can be overridden to store/load cached
compilation artifacts when embedding node.js .
@indutny
Copy link
Member Author

indutny commented Apr 19, 2016

@indutny indutny added module Issues and PRs related to the module subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Apr 19, 2016
@jasnell
Copy link
Member

jasnell commented Apr 19, 2016

hmmm... not sure about this one. What are the ramifications of exposing this?

@indutny
Copy link
Member Author

indutny commented Apr 19, 2016

Actually none. It is already possible to override this through overriding vm.runInThisContext. However it makes things more complex for embedders.

The rationale behind this patch is that I have recently tried to add V8 code cache to electron and it turned out that it is notoriously hard to do it in a clean way without copy-pasting code from the core.

@ofrobots
Copy link
Contributor

@indutny Can you elaborate on the use-case for exposing the code cache to a node embedder? What would electron do with the cached artifacts?

@indutny
Copy link
Member Author

indutny commented Apr 20, 2016

@ofrobots what's the point of introducing them in V8 in a first place? :) To speed up the compilation and to reduce the startup time?

@jasnell
Copy link
Member

jasnell commented Apr 20, 2016

I guess what I'd prefer to see on this is a proper public API as opposed to
exposing _runInThisContext directly.
On Apr 19, 2016 4:33 PM, "Fedor Indutny" notifications@github.com wrote:

Actually none. It is already possible to override this through overriding
vm.runInThisContext. However it makes things more complex for embedders.

The rationale behind this patch is that I have recently tried to add V8
code cache to electron and it turned out that it is notoriously hard to do
it in a clean way without copy-pasting code from the core.


You are receiving this because you are on a team that was mentioned.
Reply to this email directly or view it on GitHub
#6288 (comment)

@indutny
Copy link
Member Author

indutny commented Apr 20, 2016

@jasnell maybe... but we don't even have a documentation for Module.wrap and other existing methods of require('module'). Perhaps it is worth doing it prefixed first, and then moving to unprefixed version in the future?

@jasnell
Copy link
Member

jasnell commented Apr 20, 2016

Or... Perhaps only expose this if the --embedded flag is set on compile?
(See #6266).
On Apr 19, 2016 5:58 PM, "Fedor Indutny" notifications@github.com wrote:

@jasnell https://github.com/jasnell maybe... but we don't even have a
documentation for Module.wrap and other existing methods of
require('module'). Perhaps it is worth doing it prefixed first, and then
moving to unprefixed version in the future?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#6288 (comment)

@indutny
Copy link
Member Author

indutny commented Apr 20, 2016

@jasnell I'd rather not choose the second option. The embedder's code should work on regular node as much as possible. This is useful for testing, and code sharing as well.

@bnoordhuis
Copy link
Member

-1 from me, feels too much like a hack.

@benjamingr
Copy link
Member

I feel like this should be properly discussed first and that the API should look very different.

@steelbrain
Copy link

Bump

@jasnell
Copy link
Member

jasnell commented Jun 3, 2016

@nodejs/ctc ... please weigh in on this.

@rvagg
Copy link
Member

rvagg commented Jun 8, 2016

-0, every _ adds to our API debt, we know that users come to depend on them as much as "documented" APIs. I'm really not keen on exposing a hack because we don't have time to come up with something better.

Are you imagining embedders would replace this with their own wrapper to intercept for the purpose of capturing or inserting the cached version? That use is kind of like module.export.somethingPrivateThatIWantForMyTestSuite = ... which is a bit of an antipattern.

I'd even be happier with adding interceptor callbacks to the _extensions functions, something like 3rd and 4th arguments called loadCachedDataFor and saveCachedDataFor so you could override the .js extension function and add those two functions to insert and get cached data given a filename. But it seems like it might need an EP to discuss this further.

@ChALkeR
Copy link
Member

ChALkeR commented Jun 8, 2016

-1. If we want to support this, it should be a public documented api, and it most likely shouldn't be prefixed with a _.

If we don't want to support that — what's the reason for exporting it in the current state? To achieve something that is not supported by the API, embedders could just add their patches on top and support those themselves.

@rvagg
Copy link
Member

rvagg commented Jun 8, 2016

even exporting it in its current state (without _) would be a hack, it's exporting it purely for the purpose of monkeypatching, I think we can do better than that

@rvagg
Copy link
Member

rvagg commented Jun 15, 2016

CTC moved this discussion back here - we'd like to find a more elegant way of exposing this API

@jasnell
Copy link
Member

jasnell commented Mar 1, 2017

@nodejs/ctc ... looks like the was never any follow up on this. Recommend closing if we're not going to pursue it.

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 1, 2017
@fhinkel
Copy link
Member

fhinkel commented Mar 26, 2017

Feel free to reopen this PR if you get back to working on it.

@fhinkel fhinkel closed this Mar 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. semver-minor PRs that contain new features and should be released in the next minor version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants