Code Monkey home page Code Monkey logo

Comments (3)

alexandergunnarson avatar alexandergunnarson commented on July 30, 2024

In practice, WASM streaming mitigates this, but I can imagine situations where it won't be the definitive band-aid.
image

from wasm-vips.

kleisauke avatar kleisauke commented on July 30, 2024

Hi @alexandergunnarson,

Sorry for the delay. A significant portion of the vips.wasm file size comes from the foreign loaders and savers. A minimal libvips (i.e. with only core functionality) can be configured using this patch:

--- a/build.sh
+++ b/build.sh
@@ -488,11 +488,7 @@ node --version
   sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build
   meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \
     -Ddeprecated=false -Dexamples=false -Dcplusplus=$LIBVIPS_CPP -Dauto_features=disabled \
-    ${ENABLE_MODULES:+-Dmodules=enabled} -Dcgif=enabled -Dexif=enabled ${ENABLE_AVIF:+-Dheif=enabled} \
-    -Dheif-module=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \
-    -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SIMD:+-Dhighway=enabled} ${ENABLE_SVG:+-Dresvg=enabled} \
-    -Dresvg-module=enabled -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true \
-    -Dradiance=true -Dzlib=enabled
+    -Dnsgif=false -Dppm=false -Danalyze=false -Dradiance=false
   meson install -C _build --tag runtime,devel
   # Emscripten requires linking to side modules to find the necessary symbols to export
   module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1)

And by compiling with -Oz instead of -O3, using:

--- a/build.sh
+++ b/build.sh
@@ -111,7 +111,7 @@ done
 export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+nontrapping-fptoint"
 
 # Common compiler flags
-COMMON_FLAGS="-O3 -pthread"
+COMMON_FLAGS="-Oz -pthread"
 if [ "$LTO" = "true" ]; then
   COMMON_FLAGS+=" -flto"
   export RUSTFLAGS+=" -Clto -Cembed-bitcode=yes"

With that, I see:

$ ls -lh lib/*.wasm | awk '{print $5,$9}'
2.9M lib/vips-O3.wasm
2.2M lib/vips-Oz.wasm

However, most WebAssembly files are served Brotli-compressed nowadays. In the ideal case, with v0.0.8, this would mean that ~1.5MiB is transferred over the network.

$ brotli node_modules/wasm-vips/lib/vips.wasm --best -v
Compressed [node_modules/wasm-vips/lib/vips.wasm]: 5.388 MiB -> 1.509 MiB in 8.49 sec

(usually the size is ~1.8MiB due to the use of compression level 4, as shown in your screenshot)

Running the same command over the produced WebAssembly binaries above, I see:

$ brotli lib/vips-O{3,z}.wasm --best -v
Compressed [lib/vips-O3.wasm]: 2.872 MiB -> 968.115 KiB in 4.98 sec
Compressed [lib/vips-Oz.wasm]: 2.144 MiB -> 896.830 KiB in 4.26 sec

I think that modularizing every operation within wasm-vips adds unnecessary complexity to the build logic without yielding any significant benefits. We could, however, experiment with making more foreign loaders/savers as dynamic module.

Let's tag this as an enhancement.

from wasm-vips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.