Minimal build #42951
Replies: 14 comments 6 replies
-
I think this is a better fit for the node.js repo so I'm going to move it there. I'm also not aware of any such documentation so I'm going to tag it as a feature request. |
Beta Was this translation helpful? Give feedback.
-
@guest271314 I'm not sure about your use case but in terms of being able to consistently build with the minimum set possible I'm wondering if a new option that set's all of the optinos for things which are optional would make any sense. My thought is that a build option in the Makefile would be more likely to be kept up to date as options that are added versus an external doc saying to build with options x,y,z. |
Beta Was this translation helpful? Give feedback.
-
My sole use case is using JavaScript as a Native Messaging host. The Running A C++ Native Messaging host compiled as a shared library with Running a Native Messaging host is 1.5 MB. The above data requires the question to be answered: Why fetch the entire Another question: How to identify only the source code files necessary to run the above (or any pre-written JavaScript), and only build the
That is feasible, as long s we really can have an option to begin with the bare minimum from v8, uv, et al. required to run JavaScript as a native executable - distinct from the idea of removing options from a fully-featured download: we already have that. Something along the lines of Debian minimal build. That, as directly mentioned above, and for double-redundancy here, means identifying the least amount of files to run JavaScript as as native application on the users' machine. |
Beta Was this translation helpful? Give feedback.
-
The bulk of the node binary consists of V8 and ICU. You can disable the latter with the If you want something more nimble and are okay with a runtime that's more limited in scope, take a look at https://github.com/saghul/txiki.js - it's based on quickjs instead of V8. |
Beta Was this translation helpful? Give feedback.
-
Is the entire V8 mandatory? If so, why? Node.js is the flagship. I am here asking the Node.js experts how to trim the 80 MB executable to the minimal code required. I don't expect anything from any realm, yet a clear and concise answer to my inquiry is conspicuously lacking here. I am not sure why? Incapable of adaptation or scalability? Fixed in the current model? |
Beta Was this translation helpful? Give feedback.
-
It is never that easy. $ sudo apt install curl $ make
...
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindCURL.cmake:143 (find_package_handle_standard_args)
CMakeLists.txt:76 (find_package)
-- Configuring incomplete, errors occurred!
Will you help debug why |
Beta Was this translation helpful? Give feedback.
-
Pretty much. V8 has build flags you can tweak but even in its most minimal configuration, it's still pretty bulky.
There's no ready-to-regurgitate recipe, if that's what you're hoping for, you're on your own here. Good luck and post your findings. |
Beta Was this translation helpful? Give feedback.
-
Based on your reply, my findings are it is not possible. Stuck with 80MB I tried to build Node.js the other day. Hours without progress report and not completing, I had no reference point. This appear to be a severe oversight that can be corrected, given the will to do so, which I am not gathering here. |
Beta Was this translation helpful? Give feedback.
-
Too big to scale. |
Beta Was this translation helpful? Give feedback.
-
Why don't you try to compress the executables, such as upx. |
Beta Was this translation helpful? Give feedback.
-
Still uses the same amount of resources as the original $ ./upx --brute node
$ ps -eo rss,pid,euser,args:100 --sort %mem | grep -v grep | grep -i example.js | awk '{printf $1/1024 "MB"; $1=""; print }'
82.5781MB |
Beta Was this translation helpful? Give feedback.
-
This is what I have so far using https://github.com/saghul/txiki.js. On *nix a dependency is libcurl-dev, which prompt do download one of several packages with different names. I used the OpenSSL option. I am not sure why array over 63 elements length does not get sent back to the Native Messaging client. Memory used. Node.js is ~36MB. txiki.js is ~17MB. #!/path/to/tjs
// txiki.js Native Messaging host
// guest271314, 5-5-2022
(async() => {
async function getMessage() {
const buffer = new Uint8Array(4);
const input = await tjs.stdin.read(buffer);
const [length] = new Uint32Array(buffer.buffer);
const output = new Uint8Array(length);
await tjs.stdin.read(output);
return output;
}
async function sendMessage(message) {
const header = new Uint32Array(4);
header.set([message.length], 0, true);
const output = new Uint8Array(header.length + message.length);
output.set(header, 0, true);
output.set(message, 4, true);
await tjs.stdout.write(output);
return true;
}
while (true) {
const message = await getMessage();
await sendMessage(message);
}
})(); |
Beta Was this translation helpful? Give feedback.
-
I utilized QuickJS (937504 bytes executable) as a Native Messaging host with 2.8MB (which is less than Bash at 3.6MB; Python at 10MB; PHP at 15MB; C++ at 1.5MB). Node.js is most expensive as a Native Messaging host at 36MB (82MB executable). Given the movement in/of this feature request I don't think a minimal Node.js can be built (if at all) which requires less computing resources than txiki.js and QuickJS as JavaScript runtimes; nor the above listed languages. #!/usr/bin/env -S /path/to/qjs -m --std
// QuickJS Native Messaging host
// guest271314, 5-6-2022
import * as std from 'std';
import * as os from 'os';
function getMessage() {
const header = new Uint8Array(4);
std.in.read(header.buffer, 0, header.length);
// https://stackoverflow.com/a/26140545
const length = new Uint32Array(header.buffer).reduce(
(a, b, index) => a | (b << (index * 8)),
0
);
const output = new Uint8Array(length);
std.in.read(output.buffer, 0, length);
return output;
}
function sendMessage(message) {
// https://stackoverflow.com/a/24777120
const header = Uint32Array.from(
{
length: 4,
},
(_, index) => (message.length >> (index * 8)) & 0xff
);
const output = new Uint8Array(header.length + message.length);
output.set(header, 0, true);
output.set(message, 4, true);
std.out.write(output.buffer, 0, output.length);
std.out.flush();
}
while (true) {
const message = getMessage();
sendMessage(message);
} |
Beta Was this translation helpful? Give feedback.
-
Unfortunately QuickJS |
Beta Was this translation helpful? Give feedback.
-
To build and run Node.js as a minimal JavaScript runtime, with specific requirements that will not change:
process
,Buffer
,Array
,JSON
,require('child_process')
protocol.js from https://github.com/simov/native-messaging/blob/master/protocol.js
example.js
I read #2948 and nodejs/docs#88.
This is what I have tried
I did not locate an official, formal procedure to build minimal
node
.Ideally, given existing files which contain the complete code required
node
executable can be build targeting only the dependencies in the existing .js files, adding nothing else, e.g., nonpm
,WebAssembly
, SSL, etc.Currently the nightly
node
executable is ~80MB. I suspect the executable can be built less expensively, without including source code that will not be used in the resultingnode
executable.Kindly share the official procedure to build minimal
node
executable.Beta Was this translation helpful? Give feedback.
All reactions