cossacklabs / themis

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
https://www.cossacklabs.com/themis
Apache License 2.0
1.87k stars 143 forks source link

WASM size #895

Closed steida closed 2 years ago

steida commented 2 years ago

I was going to try Themis wasm, but libthemis.wasm file is huge. Even gzipped, it has roughly 1 MB. For a comparison, OpenPGP.js has roughly 100kb. Maybe there is a reason for that, but for simple E2EE, 1MB seems to be too much.

Lagovas commented 2 years ago

Themis doesn't implement any crypto primitives and uses openssl/boringssl/etc as crypto backends. For wasm themis uses BoringSSL and compiles themis library statically linked with boringssl to wasm library. Most of the final size is boringssl's code. Openpgp.js uses pure JS libraries and builtin JS Crypto API (that not calculated as additional size for library :)

ilammy commented 2 years ago

Most of the final size is BoringSSL's code.

This is true. However, libthemis.wasm does not use all of BoringSSL yet it includes it in its entirety.

Unfortunately, at the moment WasmThemis build disables dead-code elimination at link time. Because of that, the resulting binary is much bigger than it could be. DCE is disabled to work around issues with the toolchain, as my attempts to enable link-time optimizations make Emscripten think that all of WasmThemis is dead code that must be eliminated, resulting in an empty WebAssembly module. Help would be appreciated.