Skip to content

Sourceless vm.Script compilation/load #26026

Closed

Description

@danielgindi

Is your feature request related to a problem? Please describe.
Not exactly a problem, but a capability that I'd like to have in Node.js out of the box (Otherwise we need to recompile it).

Describe the solution you'd like
Currently pkg is adding a flag "sourceless" that allows compiling a vm.Script without requiring keeping the sources around. When you load the compiled script, it works and has no JS sources attached.
It does so with this patch:
https://github.com/zeit/pkg-fetch/blob/master/patches/node.v10.4.1.cpp.patch

There's much more going on in the patch, like adding pkg's bootstrap code, or using its wrapped fs/child_process functions, which is not the issue here and is not of interest for this feature request.

A cleaner patch file, exported to a gist by me can be found here: v10.x v11.x

Describe alternatives you've considered
I've tried passing dummy scripts to new vm.Script when loading the cached data, but the cachedData is rejected.
It also has the culprit of CPU compatibility, as by default node only loads the cachedData if the CPU features matches exactly, for performance reasons. Whereas pkg allows loading as long as the current CPU has at least the features of the CPU it compiled on. So it has binary compatibility, but may not use new CPU features.

I'm aware of the fact that loading sourceless compiled scripts will have some kind of a performance hit, but it's acceptable in cases where you want to have complete obfuscation, or if you want to avoid the load/parse/compile time of a huge JS script, or any other case where you might want/need to transport binaries instead of sources.

Activity

  1. added
    vmIssues and PRs related to the vm subsystem.
    v8 engineIssues and PRs related to the V8 dependency.
    feature requestIssues requesting new Node.js features.
    on Feb 10, 2019
  2. bnoordhuis commented on Feb 10, 2019

    @bnoordhuis
    Member

    Any feature request that requires changes to V8 should be contributed to that project first. We'll eventually pick them up when we upgrade or, if necessary, they could be back-ported.

  3. danielgindi commented on Feb 10, 2019

    @danielgindi
    Author

    @bnoordhuis I'm much less familiar with V8's codebase. What's the procedure there?

  4. danielgindi commented on Feb 11, 2019

    @danielgindi
    Author
  5. danielgindi commented on Feb 11, 2019

    @danielgindi
    Author

    v8's contribution process is terrible. You have to have a whole suite of tools (that do not work out of the box) just to submit a PR. And then you have to select the people who are supposed to review it. How the hell would I know? I ended up selecting some "recommended" names...

  6. hashseed commented on Feb 15, 2019

    @hashseed
    Member

    Fwiw you never really submitted your CL for review. It is still "work in progress". I just happened to come across it to give some comments.

  7. danielgindi commented on Feb 17, 2019

    @danielgindi
    Author

    @hashseed What do you mean? I did it like in the "How to contribute" guide...

  8. danielgindi commented on Feb 17, 2019

    @danielgindi
    Author

    @hashseed Also I did fix some of the issues there, and commented on other comments you had

  9. TimothyGu commented on Feb 17, 2019

    @TimothyGu
    Member

    @danielgindi You have to hit the “Start Review” button.

  10. danielgindi commented on Feb 17, 2019

    @danielgindi
    Author

    I see. Thank you. I was under the impression that "Start Review" is for the reviewer... Amazing UX.

    @hashseed I've rebased on master to resolve the conflicts as the code was touched in the same area, but I do not know how commit 6cb174b4 affects it as they removed the cpu features sanity check (was it moved somewhere else?).

  11. 8 remaining items

  12. devsnek commented on Apr 10, 2019

    @devsnek
    Member

    I think the bytecode is architecture specific since it uses the registers, but if that intel and amd are both the same architecture it shouldn't be a problem

  13. danielgindi commented on Apr 10, 2019

    @danielgindi
    Author

    So it does not contain any cpu-specific features, but it IS architecture dependent?
    I guess the AMD is the lowest common denominator between the two, otherwise I can't explain why AMD code works on Intel but not vice-versa.

    BTW - this only happens on later node versions. Specifically 10.15.3, but does not happen with 10.4.1. Which is even weirder. With 10.4.1, Intel code works on AMD.

  14. danielgindi commented on Apr 15, 2019

    @danielgindi
    Author

    @hashseed / @devsnek any ideas?

  15. hashseed commented on Apr 15, 2019

    @hashseed
    Member
  16. danielgindi commented on Apr 15, 2019

    @danielgindi
    Author

    @hashseed That's ok. Whenever you will be available, I'll love to get some input from you on this. Thank you! Have fun :-)

  17. robertsLando commented on Apr 26, 2021

    @robertsLando
    Contributor

    @danielgindi Any updates on this?

  18. github-actions commented on Mar 24, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  19. github-actions commented on Mar 24, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  20. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Mar 24, 2022
  21. moved this to Pending Triage in Node.js feature requestson Mar 24, 2022
  22. moved this from Pending Triage to Stale in Node.js feature requestson Mar 24, 2022
  23. github-actions commented on Apr 24, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.v8 engineIssues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions