-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Include heap views only when needed #27269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brendandahl
wants to merge
6
commits into
emscripten-core:main
Choose a base branch
from
brendandahl:heap-vars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9257b9
Include heap views only when needed
brendandahl 07a2029
Automatic rebaseline of codesize expectations. NFC
brendandahl f767cb7
docs
brendandahl 646db88
review comments
brendandahl a65bcda
review comments
brendandahl f8e2d97
move to python
brendandahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,13 +99,22 @@ var runtimeExited = false; | |
| shouldExport = true; | ||
| } | ||
| return shouldExport; | ||
| } | ||
| }; | ||
| const maybeExportHeap = (x) => { | ||
| if (shouldExportHeap(x) && MODULARIZE != 'instance') { | ||
| return `Module['${x}'] = `; | ||
| } | ||
| return ''; | ||
| }; | ||
| const isHeapNeeded = (x) => { | ||
| return shouldExportHeap(x) || addedLibraryItems['$' + x]; | ||
| }; | ||
| const updateHeap = (x, type) => { | ||
| if (isHeapNeeded(x)) { | ||
| return `${maybeExportHeap(x)}${x} = new ${type}(b);`; | ||
| } | ||
| return ''; | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is almost enough complexity to just move the whole updateMemoryViews into a generator / helper. But I guess it makes sense for this incremental change to do it this way for now. |
||
| }}} | ||
|
|
||
|
|
||
|
|
@@ -161,17 +170,17 @@ function updateMemoryViews() { | |
| #endif | ||
| var b = wasmMemory.buffer; | ||
| #endif | ||
| {{{ maybeExportHeap('HEAP8') }}}HEAP8 = new Int8Array(b); | ||
| {{{ maybeExportHeap('HEAP16') }}}HEAP16 = new Int16Array(b); | ||
| {{{ maybeExportHeap('HEAPU8') }}}HEAPU8 = new Uint8Array(b); | ||
| {{{ maybeExportHeap('HEAPU16') }}}HEAPU16 = new Uint16Array(b); | ||
| {{{ maybeExportHeap('HEAP32') }}}HEAP32 = new Int32Array(b); | ||
| {{{ maybeExportHeap('HEAPU32') }}}HEAPU32 = new Uint32Array(b); | ||
| {{{ maybeExportHeap('HEAPF32') }}}HEAPF32 = new Float32Array(b); | ||
| {{{ maybeExportHeap('HEAPF64') }}}HEAPF64 = new Float64Array(b); | ||
| {{{ updateHeap('HEAP8', 'Int8Array') }}} | ||
| {{{ updateHeap('HEAP16', 'Int16Array') }}} | ||
| {{{ updateHeap('HEAPU8', 'Uint8Array') }}} | ||
| {{{ updateHeap('HEAPU16', 'Uint16Array') }}} | ||
| {{{ updateHeap('HEAP32', 'Int32Array') }}} | ||
| {{{ updateHeap('HEAPU32', 'Uint32Array') }}} | ||
| {{{ updateHeap('HEAPF32', 'Float32Array') }}} | ||
| {{{ updateHeap('HEAPF64', 'Float64Array') }}} | ||
| #if WASM_BIGINT | ||
| {{{ maybeExportHeap('HEAP64') }}}HEAP64 = new BigInt64Array(b); | ||
| {{{ maybeExportHeap('HEAPU64') }}}HEAPU64 = new BigUint64Array(b); | ||
| {{{ updateHeap('HEAP64', 'BigInt64Array') }}} | ||
| {{{ updateHeap('HEAPU64', 'BigUint64Array') }}} | ||
| #endif | ||
| #if SUPPORT_BIG_ENDIAN | ||
| {{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,77 @@ | ||
| var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, C, q, D, m, E, v; | ||
| var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, B, p, C, l, D, u; | ||
|
|
||
| e && (onmessage = a => { | ||
| onmessage = null; | ||
| f = a = a.data; | ||
| g = a.o; | ||
| h(); | ||
| c ||= {}; | ||
| c.wasm = a.m; | ||
| k(); | ||
| h(); | ||
| a.m = a.o = 0; | ||
| }); | ||
|
|
||
| function h() {} | ||
|
|
||
| e || (g = new WebAssembly.Memory({ | ||
| initial: 256, | ||
| maximum: 256, | ||
| shared: !0 | ||
| }), h()); | ||
| })); | ||
|
|
||
| var l = [], n = a => { | ||
| var k = [], m = a => { | ||
| a = a.data; | ||
| var b = a._wsc; | ||
| b && m.get(b)(...a.x); | ||
| }, p = a => { | ||
| l.push(a); | ||
| }, r = () => { | ||
| q(0, !d, !e, d && 1); | ||
| }, u = {}, w = (a, b, z) => { | ||
| var t = u[a] = new Worker(c.js, { | ||
| b && l.get(b)(...a.x); | ||
| }, n = a => { | ||
| k.push(a); | ||
| }, q = () => { | ||
| p(0, !d, !e, d && 1); | ||
| }, t = {}, v = (a, b, y) => { | ||
| var r = t[a] = new Worker(c.js, { | ||
| name: "em-ww" | ||
| }); | ||
| t.postMessage({ | ||
| r.postMessage({ | ||
| A: a, | ||
| m: v, | ||
| m: u, | ||
| o: g, | ||
| u: b, | ||
| v: z | ||
| v: y | ||
| }); | ||
| t.onmessage = n; | ||
| r.onmessage = m; | ||
| return !0; | ||
| }, x = () => performance.now(), y = () => !1, A = (a, b) => { | ||
| u[a].postMessage({ | ||
| }, w = () => performance.now(), x = () => !1, z = (a, b) => { | ||
| t[a].postMessage({ | ||
| _wsc: b, | ||
| x: [] | ||
| }); | ||
| }; | ||
|
|
||
| e && (u[0] = globalThis, addEventListener("message", p)); | ||
| e && (t[0] = globalThis, addEventListener("message", n)); | ||
|
|
||
| function B() { | ||
| function A() { | ||
| console.log("Hello from wasm worker!"); | ||
| } | ||
|
|
||
| function k() { | ||
| E = { | ||
| d: r, | ||
| c: w, | ||
| b: x, | ||
| e: y, | ||
| f: A, | ||
| g: B, | ||
| function h() { | ||
| D = { | ||
| d: q, | ||
| c: v, | ||
| b: w, | ||
| e: x, | ||
| f: z, | ||
| g: A, | ||
| a: g | ||
| }; | ||
| WebAssembly.instantiate(c.wasm, { | ||
| a: E | ||
| a: D | ||
| }).then((a => { | ||
| var b = (a.instance || a).exports; | ||
| v = a.module || c.wasm; | ||
| C = b.i; | ||
| q = b.k; | ||
| D = b.l; | ||
| m = b.j; | ||
| e ? (D(f.A, f.u, f.v), removeEventListener("message", p), l = l.forEach(n), addEventListener("message", n)) : b.h(); | ||
| e || C(); | ||
| u = a.module || c.wasm; | ||
| B = b.i; | ||
| p = b.k; | ||
| C = b.l; | ||
| l = b.j; | ||
| e ? (C(f.A, f.u, f.v), removeEventListener("message", n), k = k.forEach(m), addEventListener("message", m)) : b.h(); | ||
| e || B(); | ||
| })); | ||
| } | ||
|
|
||
| e || k(); | ||
| e || h(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| var d = Module, e, f = new TextDecoder, g, h; | ||
| var c = Module, d = new TextDecoder, e, f, h; | ||
|
|
||
| WebAssembly.instantiate(d.wasm, { | ||
| WebAssembly.instantiate(c.wasm, { | ||
| a: { | ||
| a: a => { | ||
| var c = console, k = c.log; | ||
| var g = console, k = g.log; | ||
| if (a) { | ||
| for (var b = a, l = e, m = b + NaN; l[b] && !(b >= m); ) ++b; | ||
| a = f.decode(e.subarray(a, b)); | ||
| a = d.decode(e.subarray(a, b)); | ||
| } else a = ""; | ||
| k.call(c, a); | ||
| k.call(g, a); | ||
| } | ||
| } | ||
| }).then((a => { | ||
| a = a.instance.exports; | ||
| g = a.d; | ||
| f = a.d; | ||
| h = a.b; | ||
| e = new Uint8Array(h.buffer); | ||
| a.c(); | ||
| g(); | ||
| f(); | ||
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these are actually used much. Maybe add a TODO to remove them from this list?