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?