rive-app / rive-wasm

Wasm/JS runtime for Rive
MIT License
703 stars 51 forks source link

WASM file size and lighter rive engine #285

Closed flavienbonvin closed 1 year ago

flavienbonvin commented 1 year ago

Hi,

preloading the wasm file is great since it allow getting everything setup before users see animations. However, the file size is quite large and can have an impact on infrastructure (the file is 196 KB).

It would be great to see some size trimming on the wasm file to speed loading and reduce impact on infra. It could also be great to have a rive-lite.wasm engine that have a reduce set of features (state machines for examples) to avoid loading the whole file but a smaller one with less feature.

Is there some plan to reduce the file size or offer a slimmer version?

zplata commented 1 year ago

Hi @flavienbonvin ! The WASM file that gets built is already optimized for small size (especially using the canvas variant), but the bulk of the size comes from the bindings to JS from CPP (you can see in wasm/src/bindings.cpp most of the bindings to JS classes/methods/properties). We try to keep bindings down to a minimum and as-needed basis. Because a "lite" version would be hard to predict for a general user's needs, it'd be tricky to come up with an even lighter version for a WASM build.

However, what you can experiment with is forking this repo, and removing bindings you don't need for your own project. For example:

It might shave off some kB to help lessen the impact

flavienbonvin commented 1 year ago

Thanks a lot for the suggestions, I'll have a look and keep you updated of the changes (if I manage to make things work)