pyodide-pack icon indicating copy to clipboard operation
pyodide-pack copied to clipboard

Rewrite package code to reduce inter-module dependencies

Open rth opened this issue 2 years ago • 0 comments

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,

  1. Manual fixes: we could do upstream fixes, to reduce inter-module dependencies
  2. 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.

rth avatar May 09 '22 01:05 rth