Yes, the code pattern you suggest should be able to split off each function
into a separate module without any problems. I would recommend configuring
a different `placeholderNamespace` for each module you split off to make it
easy to tell which module you will need to instantiate to get the proper
replacement. In principle you could also do this by invoking wasm-split
multiple times instead of writing a custom tool. If you want to continue
tracking calls after the replacement module has been instantiated, you
should do that using a separate mechanism rather than using wasm-split's
placeholder functions, since it's a core assumption of wasm-split that the
placeholder functions will be entirely replaced.

Do note that Emscripten has no support for this kind of custom splitting,
so you'll be on your own for making the JS load and instantiate the
individual modules at runtime.


On Wed, Apr 21, 2021 at 3:56 AM Александр Гурьянов <[email protected]>
wrote:

> Hi.I have a custom optimization layer that helps me to decrease wasm
> binary size. It is a sort of PGO optimization, I have a statistic about
> each function in wasm - how many times it called. Then I remove functions
> with zero invocations from wasm and generate js version of same function to
> invoke if it suddenly needed (1 js file - 1 removed function). This
> optimization works very good except it uses js which is slow and big.
>
> Now I want to generate small wasm modules (<4Kb) instead of js versions. I
> thought that wasm-split can help, but I realized that it generates a big
> module that can't be load in synchronous way. Moreover there is another
> problem, it replaces all placeholders with actual implementation on
> instantiation. But, I don't want to replace placeholders because they
> continue to track call stats (this is minor problem, I know workaround for
> it).
>
> Is there some way to force wasm-split to generate multiple modules (1 per
> function). Something like this:
>
>   std::unique_ptr<Module> fn1 =
>     ModuleSplitting::splitFunctions(wasm, <ALL FUNCTIONS - fn1>);
>   std::unique_ptr<Module> fn2 =
>     ModuleSplitting::splitFunctions(wasm, <ALL FUNCTIONS - fn1 - fn2>);
>
> ...
>
>   ModuleWriter writer;
>   writer.setBinary(options.emitBinary);
>   writer.setDebugInfo(options.passOptions.debugInfo);
>   writer.write(wasm, options.primaryOutput);
>   writer.write(*fn1, wasmFn1);
>   writer.write(*fn2, wasmFn2);
>
> Or if it's not possible, what do you think is it doable and how hard is it?
>
> --
> 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%3DVGzr8Wr_MR4733AkKnkkyoq2ainU6kzsS9dOkVuXki7NQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVGzr8Wr_MR4733AkKnkkyoq2ainU6kzsS9dOkVuXki7NQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAJZD_EXryerDjOZD%3DjmF3eh%3DKERJLYJ4ysd%2BuRc7L-E97u6jxQ%40mail.gmail.com.

Reply via email to