Skip to content

Commit 784f327

Browse files
authored
Always await the createWasm promise under WASM_ASYNC_COMPILATION (#27075)
When `WASM_ASYNC_COMPILATION` is enabled `createWasm` returns a promise. However we were not always waiting on this and instead using the `addRunDependency` system to block the running of main. This change simplifies things by always awaiting the promise when it exists. This is kind of a followup to #27059 and a pre-cursor to #27028 which is a much larger change. Comes with a nice little codesize saving too, since it avoid the whole `addRunDependency` in most simple programs.
1 parent 74e3157 commit 784f327

49 files changed

Lines changed: 183 additions & 217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/postamble.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,13 @@ if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) {
347347
#if !MODULARIZE && WASM_ASYNC_COMPILATION
348348
// With async instantation wasmExports is assigned asynchronously when the
349349
// instance is received.
350-
createWasm();
350+
createWasm().then(() => run());
351351
#else
352352
// In modularize mode the generated code is within a factory function so we
353353
// can use await here (since it's not top-level-await).
354354
wasmExports = {{{ awaitIf(MODULARIZE && WASM_ASYNC_COMPILATION) }}}createWasm();
355-
#endif
356-
357355
{{{ awaitIf(MODULARIZE) }}}run();
356+
#endif
358357

359358
#if WASM_WORKERS || PTHREADS
360359
}

src/preamble.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,15 +794,9 @@ function getWasmImports() {
794794
#if PTHREADS || WASM_WORKERS
795795
// We now have the Wasm module loaded up, keep a reference to the compiled module so we can post it to the workers.
796796
wasmModule = module;
797-
#endif
798-
#if WASM_ASYNC_COMPILATION && !MODULARIZE
799-
removeRunDependency('wasm-instantiate');
800797
#endif
801798
return wasmExports;
802799
}
803-
#if WASM_ASYNC_COMPILATION && !MODULARIZE
804-
addRunDependency('wasm-instantiate');
805-
#endif
806800

807801
// Prefer streaming instantiation if available.
808802
#if WASM_ASYNC_COMPILATION

test/codesize/test_codesize_cxx_ctors1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19322,
3-
"a.out.js.gz": 8008,
2+
"a.out.js": 19192,
3+
"a.out.js.gz": 7944,
44
"a.out.nodebug.wasm": 132666,
55
"a.out.nodebug.wasm.gz": 49962,
6-
"total": 151988,
7-
"total_gz": 57970,
6+
"total": 151858,
7+
"total_gz": 57906,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_ctors2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19299,
3-
"a.out.js.gz": 7995,
2+
"a.out.js": 19169,
3+
"a.out.js.gz": 7931,
44
"a.out.nodebug.wasm": 132092,
55
"a.out.nodebug.wasm.gz": 49625,
6-
"total": 151391,
7-
"total_gz": 57620,
6+
"total": 151261,
7+
"total_gz": 57556,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_except.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23298,
3-
"a.out.js.gz": 8987,
2+
"a.out.js": 23166,
3+
"a.out.js.gz": 8928,
44
"a.out.nodebug.wasm": 172586,
55
"a.out.nodebug.wasm.gz": 57501,
6-
"total": 195884,
7-
"total_gz": 66488,
6+
"total": 195752,
7+
"total_gz": 66429,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_except_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19125,
3-
"a.out.js.gz": 7925,
2+
"a.out.js": 18995,
3+
"a.out.js.gz": 7862,
44
"a.out.nodebug.wasm": 147991,
55
"a.out.nodebug.wasm.gz": 55370,
6-
"total": 167116,
7-
"total_gz": 63295,
6+
"total": 166986,
7+
"total_gz": 63232,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_except_wasm_legacy.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19199,
3-
"a.out.js.gz": 7955,
2+
"a.out.js": 19069,
3+
"a.out.js.gz": 7884,
44
"a.out.nodebug.wasm": 145797,
55
"a.out.nodebug.wasm.gz": 54992,
6-
"total": 164996,
7-
"total_gz": 62947,
6+
"total": 164866,
7+
"total_gz": 62876,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_lto.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 18662,
3-
"a.out.js.gz": 7691,
2+
"a.out.js": 18532,
3+
"a.out.js.gz": 7634,
44
"a.out.nodebug.wasm": 102168,
55
"a.out.nodebug.wasm.gz": 39572,
6-
"total": 120830,
7-
"total_gz": 47263,
6+
"total": 120700,
7+
"total_gz": 47206,
88
"sent": [
99
"a (emscripten_resize_heap)",
1010
"b (_setitimer_js)",

test/codesize/test_codesize_cxx_mangle.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23348,
3-
"a.out.js.gz": 9009,
2+
"a.out.js": 23216,
3+
"a.out.js.gz": 8947,
44
"a.out.nodebug.wasm": 239015,
55
"a.out.nodebug.wasm.gz": 79854,
6-
"total": 262363,
7-
"total_gz": 88863,
6+
"total": 262231,
7+
"total_gz": 88801,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_noexcept.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19322,
3-
"a.out.js.gz": 8008,
2+
"a.out.js": 19192,
3+
"a.out.js.gz": 7944,
44
"a.out.nodebug.wasm": 134666,
55
"a.out.nodebug.wasm.gz": 50806,
6-
"total": 153988,
7-
"total_gz": 58814,
6+
"total": 153858,
7+
"total_gz": 58750,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

0 commit comments

Comments
 (0)