Interesting! One probem here would be that a wasm module can have global variables that are not exported. You'd need to export them so that JS on the outside can see them.
Another issue is JS has slightly different semantics than wasm, like unalignd loads and stores are different. This is usually not an issue, but it may be a source of bugs. I am actually going to implement something very similar to this, using the approach in your last point - asyncify. The idea is with asyncify you will block when you try to call functions that are not shipped in the first download, and you then download and compile the complete module (which includes everything - that avoids the unexported globals issue, and allows for full speed of calls later) and then resume into the complete module I hope to have a prototype soon (but have several other urgent things, so it may take a little time). - Alon On Tue, Sep 3, 2019 at 4:11 AM Александр Гурьянов <[email protected]> wrote: > Hi guys. I have very special use case to implement. My application > have very big wasm: 19Mb, but I know that really used part (core) is > 7Mb. I have names of all functions that are used in core part. Now I > trying to minimize wasm file to 7Mb. > > Currently I just drop all functions that not in this list, and my wasm > is 7mb. But, of course rarely application crashed when tries to > execute dropped function. I want to create solution that works in 100% > cases. Again, my target is to have minimal possible wasm file with > core functions. > > My idea is to use wasm2js or wasm2asm to generate js function in > addtion to wasm binary. > Generation flow: > 1. For wasm function that not in list > 2. genearte js code from wasm body (wasm2js/wsam2asm?) > 3. replace body with call to js compliant function > > Loading: > 1. Load wasm > 2. Load sources of js compliant functions > 3. Run wasm, when code ask to eval compliant function - create this > function (from source) and run > > So my questions: > 1. Is this flow will work, how do you think? > 2. Can I use wasm2js/wasm2asm to generate js functions? > 3. Can I use asyncify to load this functions by xhr at eval time? > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHNBYbK9mq%3DuErM_Oea5vNzVAeHbqypztp-0DxR0VZzfg%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpTiXoxc3EvSvigjjQAwaq9vkxV1MnFA2dUrXg2CHmNx1w%40mail.gmail.com.
