wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Reduce the binary size

Open kvark opened this issue 4 years ago • 5 comments

See https://twitter.com/batmansmk/status/1346479574465433613 A simple app got compiled to an 1.3Mb executable. I'm sure we can do better!

kvark avatar Jan 05 '21 18:01 kvark

This is espcially important on wasm/webgl, where the blob has to be shipped over the wire. Currently our examples, built in release, sit at about 5-6MB uncompressed.

cwfitzgerald avatar Jan 16 '21 09:01 cwfitzgerald

I can confirm this for WebGL builds. Not for builds which use WebGPU. I'm currently at 1.6Mb uncompressed (Gziped its 571k.). The reason for this could also be that winit, web-sys or js-sys introduces this issue. I haven't debugged the root cause so far.

Steps I've completed so far:

  • Build in release profile
  • Enable optimizations for release profile:
    [profile.release]
    lto = true
    codegen-units = 1
    opt-level = 's'
    
  • Run wasm-opt
  • Disabling unused features like "x11", "wayland" for winit

Further ideas: https://rustwasm.github.io/book/reference/code-size.html

I think that the uncompressed size should be below 1Mb, else the compilation on the client side could be a real bottleneck (CPU fans spin up etc.). In comparison for WebGPU my build size is already 708k without compression (compressed its down to 222k).

maxammann avatar Dec 10 '21 08:12 maxammann

@kvark did you use the WebGL backend or WebGPU?

maxammann avatar Dec 10 '21 09:12 maxammann

I didn't measure either, just linked to a tweet.

kvark avatar Dec 10 '21 14:12 kvark

I didn't measure either, just linked to a tweet.

I might do some better reproducible measurements soon :) Something that would be awesome would be a CI step which validates that WASM builds are not exploding in size. If the size of the wasm file doubles for example with the introduction of a commit then there is a serious problem.

maxammann avatar Dec 10 '21 15:12 maxammann

This has no particular actionability, so I'm going to close.

cwfitzgerald avatar Oct 14 '23 04:10 cwfitzgerald