Closed Bug 1529957 Opened 9 months ago Closed 8 months ago

LazyStubs double overall code memory usage in AutoCAD

Categories

(Core :: Javascript: WebAssembly, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: luke, Assigned: luke)

Details

Attachments

(4 files)

web.autocad.com has a 40mb .wasm file. For this, we generate:

Tier Baseline:
ModuleSegment code: 157,024,256 bytes
LazyStubs code: 273,416,192 bytes
Tier Ion:
ModuleSegment code: 106,954,752 bytes
LazyStubs code: 41,287,680 bytes

Thus LazyStubs are more than doubling overall memory usage. Between the two of these, we spend a total of 3.6 seconds just in LazyStubTier::createOne() (on a JS main thread; fortunately a Worker in AutoCAD). It looks like we're making >64k createOne() calls.

The problem with createOne() is that it allocates a whole 4kb page for a single pair of JIT/interp entry stubs.

More investigation is needed, but my suspicious is that the JS code is eagerly walking through every export (or, more likely, Table element), creating JSFunction wrappers. This suggests being lazier with stub creation, only creating stubs when the JSFunction is actually called.

This makes me realize that, if Emscripten dynamic linking is used, then there will be thousands of exports that are only ever called by another wasm module (thereby requiring no stubs). So this "don't allocate stub until actually called" optimization might be quite valuable.

Other ideas:

  • better batching (to better utilize each 4kb page)
  • separating interp vs. JIT entries

This turns out to be rather easy (I think; I still need to verify the memory improvement on an opt build).

In the process, I noticed that the wasm table functions were erroneously accepting asm.js functions because they were using the wrong predicate.

Re-testing comment 0, the total memory usage (for WebAssembly.Instance) goes from 658mb to 355mb and the number of createOne() calls drops for >64k to <7k.

Pushed by lwagner@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/8fc0d70bdba1
Baldr: allow wasm functions to have func indices (r=bbouvier)
https://hg.mozilla.org/integration/mozilla-inbound/rev/5de97868cb80
Baldr: don't require WASM_CODEGEN_DEBUG for JitOptions that disable opts (r=bbouvier)
https://hg.mozilla.org/integration/mozilla-inbound/rev/ace72ffa3103
Baldr: create lazy stubs even more lazily (r=bbouvier)
https://hg.mozilla.org/integration/mozilla-inbound/rev/babe08d04201
Baldr: don't accept asm.js functions for table elements (r=bbouvier)
Pushed by lwagner@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/282f0d42dfc0
Fix test for platforms without asm.js support (r=me)
You need to log in before you can comment on or make changes to this bug.