ctm / mb2-doc

Mb2, poker software
https://devctm.com
7 stars 2 forks source link

investigate replacing serde_cbor with postcard #991

Closed ctm closed 2 years ago

ctm commented 2 years ago

Look into replacing serde_cbor with postcard.

The serde_cbor crate is archived. Postcard has just reached 1.0.0 and uses variable length number encodings. I think it should be possible to add postcard and make a call to encrypt using postcard and figure out the difference in size. There shouldn't be any significant increase. If not, the next thing to do is to build a binary using only postcard and compare the size of the binary (LTO it, strip it and check the compressed and non-compressed sizes) and make sure we don't get unacceptable bloat.

As it is, our WASM size is currently huge due (#549) to all the serde monomorphizations. If postcard doesn't dramatically increase the size, it's makes sense to replace it ASAP and worry about bloat later.

ctm commented 2 years ago

Postcard saves bytes on the wire (the number of bytes saved is the number of bytes smaller the postcard serialization is than the cbor_minimal; in no case did postcard result in a larger serialization):

INFO  [mb2_commands::cbor_minimal] saved 313 bytes
INFO  [mb2_commands::cbor_minimal] saved 3 bytes
INFO  [mb2_commands::cbor_minimal] saved 25 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 7 bytes
INFO  [mb2_commands::cbor_minimal] saved 3 bytes
INFO  [mb2_commands::cbor_minimal] saved 5 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 5 bytes
INFO  [mb2_commands::cbor_minimal] saved 6 bytes
INFO  [mb2_commands::cbor_minimal] saved 1034 bytes
INFO  [mb2_commands::cbor_minimal] saved 19 bytes
INFO  [mb2_commands::cbor_minimal] saved 7 bytes
INFO  [mb2_commands::cbor_minimal] saved 998 bytes
INFO  [mb2_commands::cbor_minimal] saved 3 bytes
INFO  [mb2_commands::cbor_minimal] saved 6 bytes
INFO  [mb2_commands::cbor_minimal] saved 6 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 4 bytes
INFO  [mb2_commands::cbor_minimal] saved 48 bytes
INFO  [mb2_commands::cbor_minimal] saved 14 bytes
INFO  [mb2_commands::cbor_minimal] saved 7 bytes
INFO  [mb2_commands::cbor_minimal] saved 19 bytes
INFO  [mb2_commands::cbor_minimal] saved 1034 bytes
INFO  [mb2_commands::cbor_minimal] saved 19 bytes
INFO  [mb2_commands::cbor_minimal] saved 7 bytes
INFO  [mb2_commands::cbor_minimal] saved 998 bytes
INFO  [mb2_commands::cbor_minimal] saved 3 bytes
INFO  [mb2_commands::cbor_minimal] saved 6 bytes

Postcard also compiles to smaller code. I didn't apply lto, but using the options we normally deploy from, we went from: ./pkg/index_bg.wasm 1.18 KiB (javascript) 9.39 MiB (webassembly) [built] [code generated] to ./pkg/index_bg.wasm 1.18 KiB (javascript) 3.95 MiB (webassembly) [built] [code generated] and the resultant tar file went from 437426688 Jun 24 05:26 202206240509.tar to 416141824 Jun 24 07:21 202206240710.tar So, I've upgraded to postcard and removed all traces of cbor. I'm deploying now.