You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I've come across a couple of size optimizations, which may sound interesting. By default, Alpine Linux builds packages with -Os GCC flag, which optimizes compiled binaries for size. By setting CFLAGS="-Os", I was able to reduce size of 3.8-alpine3.11 image from 112 MB to 83.9 MB (25% smaller). Also, Alpine Linux runs strip on all compiled binaries. AFAIK we can imitate that by setting LDFLAGS="-Wl,--strip-all", which strips all symbols from compiled binaries. After setting it, the image size was further reduced to 67.3 MB (40% smaller). Any thoughts?
Any chance this change might make it in? This could be a big benefit for users of this image. Is there any reason NOT to do either CFLAGS="-Os" or LDFLAGS="-Wl,--strip-all"?
Thanks @J0WI for pointing that out. But isn't this phenomenon specific to Python? Could we still considered it for other apps like PHP? Also, LDFLAGS="-Wl,--strip-all" should be safe in this case.
Activity
tianon commentedon Jan 14, 2020
Interesting! I'm a bit wary of sacrificing performance for size (as
-Osmight), but I think stripping is probably very reasonable.lubo commentedon Jan 14, 2020
I've stumbled upon GCC Compiler Tests At A Variety Of Optimization Levels Using Clear Linux. Although it was done on Clear Linux, I'd guess the performance ratios are roughly the same on Alpine. As you can see, one size doesn't fit all, but
-Osdoes IMO pretty well.J0WI commentedon Jan 16, 2020
See also tianon/dockerfiles#76 (comment)
autoferrit commentedon May 13, 2020
Any chance this change might make it in? This could be a big benefit for users of this image. Is there any reason NOT to do either
CFLAGS="-Os"orLDFLAGS="-Wl,--strip-all"?J0WI commentedon May 13, 2020
-Osoverwrites--enable-optimizationsand has a significant impact on performance: https://gitlab.alpinelinux.org/alpine/aports/-/issues/11129lubo commentedon May 13, 2020
Thanks @J0WI for pointing that out. But isn't this phenomenon specific to Python? Could we still considered it for other apps like PHP? Also,
LDFLAGS="-Wl,--strip-all"should be safe in this case.autoferrit commentedon May 13, 2020
That makes sense. I tested the LDFLAGS locally and worked well for building. I made PR #483 for this in case we want to implement it.
tianon commentedon May 19, 2020
Fixed via #483 👍