Hacker News new | ask | show | jobs
by brianm 2196 days ago
I was curious about this, so applied the easy ones for an existing tool (https://github.com/brianm/wsf).

This was not an exhaustive test of optimization combinations, just a single stack, but the results are interesting!

To read the table: default is no changes in the release profile, ie:

  [profile.release]
  # opt-level = 'z'
  # lto = true
  # panic = 'abort'
  # codegen-units = 1
After that each additional line gets uncommented and rebuilt, then sizes recorded before and after cargo-strip, so the final line is all four optimizations applied.

Results:

                       as generated    after cargo-strip
  default              8675776         5069328
  opt-level = 'z'      9023200         4676112
  lto = true           5943312         3586584
  panic = 'abort'      5062456         3135928
  codegen-units = 1    4747000         3013048
Tests run on ubuntu 20.04 (Linux d2836c103a22 5.4.0-37-generic #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020 x86_64 GNU/Linux) with

  rustc 1.43.1 (8d69840ab 2020-05-04)  
  cargo 1.43.0 (2cbe9048e 2020-05-03)  
  cargo-strip - reduces the size of binaries using the `strip` command 0.2.2  
Fascinatingly, opt-level='z' produced a LARGER binary than the default, before stripping. That was unexpected.

-Brian

1 comments

Do you think you could get it down to 300kb?
I doubt it, the dependency chain is pretty big: https://gist.github.com/brianm/066797531d8cc1f1c6c563ea8db7b...