python-wasm icon indicating copy to clipboard operation
python-wasm copied to clipboard

Lazy load infrequently used modules?

Open emmatyping opened this issue 3 years ago • 6 comments

The build scripts now load all of the modules that aren't already removed from a zip file, but one thing we could do is lazy load things instead, only putting the most frequently used modules in the browser cache (which we are close to maxing out, I think they are often 20-50MB, and the data assets are just over 20MB).

emmatyping avatar Nov 27 '21 16:11 emmatyping

We've cut things down to under 15MB so I think we don't need to do this. If we add more modules and the binary size creeps back up I think we could consider doing this.

emmatyping avatar Dec 02 '21 12:12 emmatyping

Do we have an easy way to keep an eye on the build size to help make sure we don't blow it out? Maybe something as part of CI if we get near/hit 20 MB?

brettcannon avatar Dec 02 '21 19:12 brettcannon

Yeah we should do certain checks that what we are building is reasonable (e.g. that it includes zlib, that we are under 20MB, etc).

emmatyping avatar Dec 03 '21 06:12 emmatyping

Is this worth keeping open? Or should we be working towards a solution?

brettcannon avatar Feb 11 '22 20:02 brettcannon

I've been thinking about this a bit recently.

I think a lot of people will want to only include certain modules (whether Python or C) and add custom libraries, since binary size is important in a lot of Emscripten compiled scenarios.

See also https://github.com/ethanhs/python-wasm/issues/60 and https://github.com/pyodide/pyodide/issues/646

Loading minimal CPython then lazy loading the rest seems like a reasonable thing to do, but I'm not sure if that part belongs in CPython :)

emmatyping avatar Feb 11 '22 21:02 emmatyping

I think we should allow for the possibility, but I don't think we should be the ones implementing the functionality if it requires JS code (else we are making design decisions that may not mesh with what people want/need).

brettcannon avatar Feb 11 '22 23:02 brettcannon