Skip to content

Commit 2169998

Browse files
committed
Don't force the use of imported memory under WASM2JS
Setting `IMPORTED_MEMORY` can have other implications and don't want t by default just because we chose WASM2JS. There is a slight code size regression that looks like it comes from acorn/closure not being able to cleanup up the unused calls to `new Uint8Array` in the generated content, but I'm not sure its worth pursuing them. See emscripten-core#21071
1 parent 72c3be3 commit 2169998

6 files changed

+73
-60
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17917,
5-
"a.js.gz": 8089,
4+
"a.js": 17939,
5+
"a.js.gz": 8114,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21607,
9-
"total_gz": 11161
8+
"total": 21629,
9+
"total_gz": 11186
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17395,
5-
"a.js.gz": 7900,
4+
"a.js": 17411,
5+
"a.js.gz": 7945,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21085,
9-
"total_gz": 10972
8+
"total": 21101,
9+
"total_gz": 11017
1010
}

test/code_size/hello_world_wasm2js.js

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,73 @@
1-
var b = Module, g = new function(a) {
2-
this.buffer = new ArrayBuffer(65536 * a.initial);
3-
}({
4-
initial: 256,
5-
maximum: 256
6-
}), k = g.buffer, d = new Uint8Array(k), l = new TextDecoder("utf8"), m;
1+
var c = Module, g, h, k = new TextDecoder("utf8"), l;
72

8-
function c(a) {
9-
this.exports = function(h) {
10-
function n(f) {
11-
f.set = function(e, p) {
12-
this[e] = p;
3+
function d(b) {
4+
this.exports = function(f) {
5+
function m(e) {
6+
e.set = function(a, n) {
7+
this[a] = n;
138
};
14-
f.get = function(e) {
15-
return this[e];
9+
e.get = function(a) {
10+
return this[a];
1611
};
17-
return f;
12+
return e;
1813
}
19-
return function(f) {
20-
var e = f.a.a;
14+
return function(e) {
15+
var a = new ArrayBuffer(16777216);
16+
new Int8Array(a);
17+
new Int16Array(a);
18+
new Int32Array(a);
19+
new Uint8Array(a);
20+
new Uint16Array(a);
21+
new Uint32Array(a);
22+
new Float32Array(a);
23+
new Float64Array(a);
24+
var n = e.a.a;
25+
e = m([]);
2126
return {
22-
b: function() {},
23-
c: function(p, q) {
24-
e(1024);
27+
b: Object.create(Object.prototype, {
28+
grow: {},
29+
buffer: {
30+
get: function() {
31+
return a;
32+
}
33+
}
34+
}),
35+
c: function() {},
36+
d: function(p, q) {
37+
n(1024);
2538
return 0;
2639
},
27-
d: n([])
40+
e: e
2841
};
29-
}(h);
30-
}(a);
42+
}(f);
43+
}(b);
3144
}
3245

33-
(function(a, h) {
46+
(function(b, f) {
3447
return {
35-
then: function(n) {
36-
n({
37-
instance: new c(h)
48+
then: function(m) {
49+
m({
50+
instance: new d(f)
3851
});
3952
}
4053
};
41-
})(b.wasm, {
54+
})(c.wasm, {
4255
a: {
43-
a: a => {
44-
var h = console, n = h.log;
45-
if (a) {
46-
for (var f = a + void 0, e = a; !(e >= f) && d[e]; ) ++e;
47-
a = l.decode(d.subarray(a, e));
48-
} else a = "";
49-
n.call(h, a);
50-
},
51-
memory: g
56+
a: b => {
57+
var f = console, m = f.log;
58+
if (b) {
59+
for (var e = b + void 0, a = b; !(a >= e) && g[a]; ) ++a;
60+
b = k.decode(g.subarray(b, a));
61+
} else b = "";
62+
m.call(f, b);
63+
}
5264
}
53-
}).then((a => {
54-
a = a.instance.exports;
55-
m = a.c;
56-
d.set(new Uint8Array(b.mem), 1024);
57-
a.b();
58-
m();
65+
}).then((b => {
66+
b = b.instance.exports;
67+
l = b.d;
68+
h = b.b;
69+
g = new Uint8Array(h.buffer);
70+
g.set(new Uint8Array(c.mem), 1024);
71+
b.c();
72+
l();
5973
}));
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 671,
33
"a.html.gz": 430,
4-
"a.js": 694,
5-
"a.js.gz": 433,
4+
"a.js": 862,
5+
"a.js.gz": 483,
66
"a.mem": 6,
77
"a.mem.gz": 32,
8-
"total": 1371,
9-
"total_gz": 895
8+
"total": 1539,
9+
"total_gz": 945
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 17331,
3-
"a.html.gz": 7543,
4-
"total": 17331,
5-
"total_gz": 7543
2+
"a.html": 17346,
3+
"a.html.gz": 7554,
4+
"total": 17346,
5+
"total_gz": 7554
66
}

tools/link.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,8 +1445,7 @@ def check_memory_setting(setting):
14451445
(options.shell_path == DEFAULT_SHELL_HTML or options.shell_path == utils.path_from_root('src/shell_minimal.html')):
14461446
exit_with_error(f'Due to collision in variable name "Module", the shell file "{options.shell_path}" is not compatible with build options "-sMODULARIZE -sEXPORT_NAME=Module". Either provide your own shell file, change the name of the export to something else to avoid the name collision. (see https://github.com/emscripten-core/emscripten/issues/7950 for details)')
14471447

1448-
# TODO(sbc): Remove WASM2JS here once the size regression it would introduce has been fixed.
1449-
if settings.SHARED_MEMORY or settings.RELOCATABLE or settings.ASYNCIFY_LAZY_LOAD_CODE or settings.WASM2JS:
1448+
if settings.SHARED_MEMORY or settings.RELOCATABLE or settings.ASYNCIFY_LAZY_LOAD_CODE:
14501449
settings.IMPORTED_MEMORY = 1
14511450

14521451
if settings.WASM_BIGINT:

0 commit comments

Comments
 (0)