Repository navigation
Sourceless vm.Script compilation/load #26026
Description
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
bnoordhuis commentedon Feb 10, 2019
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.
danielgindi commentedon Feb 10, 2019
@bnoordhuis I'm much less familiar with V8's codebase. What's the procedure there?
devsnek commentedon Feb 10, 2019
https://www.chromium.org/developers/contributing-code
https://v8.dev/docs/contribute
danielgindi commentedon Feb 11, 2019
https://chromium-review.googlesource.com/c/v8/v8/+/1462961
danielgindi commentedon Feb 11, 2019
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...
hashseed commentedon Feb 15, 2019
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.
danielgindi commentedon Feb 17, 2019
@hashseed What do you mean? I did it like in the "How to contribute" guide...
danielgindi commentedon Feb 17, 2019
@hashseed Also I did fix some of the issues there, and commented on other comments you had
TimothyGu commentedon Feb 17, 2019
@danielgindi You have to hit the “Start Review” button.
danielgindi commentedon Feb 17, 2019
I see. Thank you. I was under the impression that "Start Review" is for the reviewer... Amazing UX.
@hashseed I've rebased on
masterto 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?).8 remaining items
devsnek commentedon Apr 10, 2019
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
danielgindi commentedon Apr 10, 2019
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.
danielgindi commentedon Apr 15, 2019
@hashseed / @devsnek any ideas?
hashseed commentedon Apr 15, 2019
danielgindi commentedon Apr 15, 2019
@hashseed That's ok. Whenever you will be available, I'll love to get some input from you on this. Thank you! Have fun :-)
robertsLando commentedon Apr 26, 2021
@danielgindi Any updates on this?
github-actions commentedon Mar 24, 2022
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.
github-actions commentedon Mar 24, 2022
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.
github-actions commentedon Apr 24, 2022
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.