Closed Bug 1529957 Opened 9 months ago Closed 8 months ago

LazyStubs double overall code memory usage in AutoCAD


(Core :: Javascript: WebAssembly, enhancement)

Not set



Tracking Status
firefox68 --- fixed


(Reporter: luke, Assigned: luke)



(4 files) 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
Baldr: allow wasm functions to have func indices (r=bbouvier)
Baldr: don't require WASM_CODEGEN_DEBUG for JitOptions that disable opts (r=bbouvier)
Baldr: create lazy stubs even more lazily (r=bbouvier)
Baldr: don't accept asm.js functions for table elements (r=bbouvier)
Pushed by
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.