photon icon indicating copy to clipboard operation
photon copied to clipboard

Reduce size of wasm build

Open garygreen opened this issue 3 years ago • 4 comments

Currently it seems the wasm build is 1.04MB and once gzipped becomes 371KB.

The gzipped size is pretty decent, though I wonder is it possible to reduce the size even further?

Our main use case for this library is to resize pictures client side before we send them onto our server. We don't need any filtering based features, like filters, tints, effects.

I wonder if there could be a "core" wasm binary that handles the most common use cases of resizing, etc. Then an "effects" or "extended" wasm library that handles more advanced image manipulations?

Possibly some useful resources:

https://dev.bitolog.com/minimizing-go-webassembly-binary-size/ https://tuananh.org/2019/07/01/tips-on-reducing-wasm-file-size-with-emscripten/ https://hacks.mozilla.org/2018/01/shrinking-webassembly-and-javascript-code-sizes-in-emscripten/ https://dev.to/sendilkumarn/reduce-your-webassembly-binaries-72-from-56kb-to-26kb-to-16kb-40mi

garygreen avatar May 05 '21 02:05 garygreen

@garygreen I could create a separate npm package, which contains the core resizing functionality only if you like? I could definitely see this being useful for developers who only want to resize images client-side, so I'd definitely be interested in creating this.

It's also possible to optimize for size instead of speed, similar to the optimization articles linked. Currently the wasm build is optimized for speed, in order to maximise performance (using wasm-opt), however if you wish to optimize build size, that can be done also. I may have to carry out some benchmarks to see how much of a performance hit is incurred if the build is optimized for size instead.

silvia-odwyer avatar May 05 '21 02:05 silvia-odwyer

@silvia-odwyer that's awesome your open to the idea of having two separate releases!

I could be wrong in this statement but I do think the primary attraction of this library for those intending to use it on the web in WASM will be using it for resizing of images, cropping, and sending onto server. There could be people using it for a full blown built-in photoshop like app, but I think for most that isn't their primary attraction.

image

The one highlighted in yellow "Transformations" I would consider the primary functionality people need, and possibility Image Correction. The rest are all great features but are for more specific use cases.

So if we could have one release that is like 50KB in size that focusses on some core mechanics that can be used on the web that would be awesome.

It's a no brainer - download a 50KB wasm file to resize a 10MB image client side and send onto the server. Yes please 😁

garygreen avatar May 05 '21 15:05 garygreen

Provided there has not been a version released, it is trivial to modify lib.rs to not import the uneeded modules and rebuild

boehs avatar Aug 02 '21 01:08 boehs

It is possible from Rust side to add features to enable the different additional functions that photon has, however, I'm not aware of npm features that allow this.

Indeed it makes sense to have photon-core or photon-transformations that will have only the transformations.

As for the optimizations - I'm curious to hear more about this but it seems that you either choose if your wasm package will be faster when used or smaller in size.

elpiel avatar Oct 23 '21 10:10 elpiel