pyodide-pack
pyodide-pack copied to clipboard
Rewrite package code to reduce inter-module dependencies
One reason why this bundler is not able to reduce sizes that much is because of the convention of using top-level imports in Python. With top-level imports, even if a functionality is required for a function that we don't use, if we use other functions from that module, it would have to be included. This is particularly problematic for dynamic libraries which take a long time to load.
There are two ways around this,
- Manual fixes: we could do upstream fixes, to reduce inter-module dependencies
- Automatic code rewrites: one could imagine, under some conditions, trying to rewrite all code (e.g. via AST) to move top level imports under the functions / methods where they are used. Maybe starting by doing this only for .so libraries, and or imports used only a few times.