emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

SIDE_MODULE DCE according to another SIDE_MODULE

Open Keillion opened this issue 3 years ago • 3 comments

SIDE_MODULE can DCE normally according to another SIDE_MODULE.

sideModule DCE all symbols, instead of keepalive symbols needed by cModule.

#17354

I'm not very familiar with process_dynamic_libs and may need to check further if such changes are correct.

Self test: https://github.com/Keillion/emsdk-cheatlist/tree/b9a4bd64c51659a7a5d3230de9b47ae2376844bd

Keillion avatar Jul 04 '22 13:07 Keillion

@Keillion @sbc100 I find myself requiring this functionality as well. Is this still something that's still worth considering? If so I'll try extending some tests to cover this scenario so that we can merge this PR.

Mintyboi avatar Oct 17 '25 05:10 Mintyboi

@Mintyboi My suggestion is, don't go this route for now, it's too complicated. A small change may require recompiling the entire so many wasms.

The route I currently recommend is:

  • Try to concentrate your functionality in one wasm.
  • If you must have two wasms to load on demand, let them interact with each other using the extern "C" interface. No need webidl and no need embind. If you need handle some bytes, it need to be copied from wasm to another (copy parts of wasm1's HEAP8 into wasm2's parts of HEAP8).
  • Optimize the size of each wasm itself. They do not need to be compatible with each other in ABI (Application Binary Interface). You can improve a single wasm at any time without recompiling the others. You can use different optimization strategies for different wasm, some focusing on size and some focusing on performance.
  • Ensure that the interactions within a single wasm are far more frequently than the interactions between wasms, so that the cost of copying will not be significant.

Keillion avatar Oct 21 '25 03:10 Keillion

@Keillion Thanks for the recommendation and detailed analysis.

I'm currently in a situation where it's tricky or even impossible to refactor the codebase. I am building 1 side module (sideyA) and there's 2 other modules (sideyB and sideyC which is not built by my team) which are dependent on sideyA. In the end, all 3 side modules (sideyA,B,C) will be loaded into my main application on demand.

I need to make sure that I am exporting all the necessary symbols to sideyB and sideyC. And am currently maintaining an export file which I pass into -sEXPORTED_FUNCTIONS while building sideyA. To reduce maintenance, I was thinking that I could link sideyB and sideyC as dependencies while building sideyA and let process_dynamic_libs handle the export like what you have done in this PR.

Mintyboi avatar Nov 06 '25 07:11 Mintyboi