Hi. I created a test program to estimate performance of my program. I
am trying to use it both in browser and node environment. Test program
works fine in both environments. However startups in node took up to
30 sec, while in browser it starts instantly. I don’t understand why.
I use an release build with -s ASYNCIFY = 1, my node.js script:
```
const { performance } = require('perf_hooks');
const dhry2 = require("./dhry2.js");
const startedAt = performance.now();
const Module = {
log: console.log,
performance,
onRuntimeInitialized: () => {
console.log("Runtime initialized after", performance.now() -
startedAt, "ms");
Module.callMain([]);
},
};
dhry2(Module);
```
And for browser:
```
<!DOCTYPE html>
<html>
<head>
<script src="dhry2.js"></script>
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<button onclick="javascript:start()">Start</button>
<br/>
<div id="stdout"></div>
<script>
var stdout = document.getElementById("stdout");
function start() {
WDHRY2({
log: function(message) {
},
print: function(message) {
if (message.startsWith("dhry2")) {
console.log(message);
stdout.innerHTML = stdout.innerHTML + "<br/>"
+ message;
}
},
}).then(function(m) {
m.callMain([]);
});
};
</script>
</body>
</html>
```
Node.js version starts in 30 sec, while browser versions starts
immediately. Node hangs after leaving instantiateArrayBuffer and
before entering receiveInstantiatedSource.
I think it doing something, but I don't understand what. I profiled
node but results is no obvious:
```
Statistical profiling result from isolate-0x36df400-1353021-v8.log,
(28109 ticks, 0 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
44 0.2% /home/caiiiycuk/sdk/emsdk/node/12.18.1_64bit/bin/node
5 0.0% /usr/lib/x86_64-linux-gnu/
libc-2.31.so
1 0.0% /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28
[JavaScript]:
ticks total nonlib name
1 0.0% 0.0% Function: *wasm-function[2219]
[C++]:
ticks total nonlib name
27974 99.5% 99.7% __pthread_cond_wait
35 0.1% 0.1%
node::native_module::NativeModuleEnv::CompileFunction(v8::FunctionCallbackInfo<v8::Value>
const&)
...
[Summary]:
ticks total nonlib name
1 0.0% 0.0% JavaScript
28058 99.8% 100.0% C++
...
[C++ entry points]:
ticks cpp total name
45 76.3% 0.2% v8::internal::Builtin_HandleApiCall(int,
unsigned long*, v8::internal::Isolate*)
3 5.1% 0.0% node::inspector::(anonymous
namespace)::InspectorConsoleCall(v8::FunctionCallbackInfo<v8::Value>
const&)
[Bottom up (heavy) profile]:
Note: percentage shows a share of a particular caller in the total
amount of its parent calls.
Callers occupying less than 1.0% are not shown.
ticks parent name
27974 99.5% __pthread_cond_wait
```
I attached the build with -g you can test it both in browser and node.
(link:
https://drive.google.com/file/d/1lucme6dv-9D5yB-Wu9PieUjY5ag0YvxY/view?usp=sharing)
borwser: dhry2.html
node: node dhry2_node.js