Received: from mx1.tetrasec.net (mx1.tetrasec.net [66.245.176.36]) by nld3-dev1.alpinelinux.org (Postfix) with ESMTPS id 0778D78177F for <~alpine/devel@lists.alpinelinux.org>; Tue, 7 Jul 2020 12:06:50 +0000 (UTC) Received: from mx1.tetrasec.net (mail.local [127.0.0.1]) by mx1.tetrasec.net (Postfix) with ESMTP id 6594CCD50B; Tue, 7 Jul 2020 12:06:48 +0000 (UTC) Received: from ncopa-desktop.copa.dup.pw (67.63.200.37.customer.cdi.no [37.200.63.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: alpine@tanael.org) by mx1.tetrasec.net (Postfix) with ESMTPSA id D2D33CD50A; Tue, 7 Jul 2020 12:06:47 +0000 (UTC) Date: Tue, 7 Jul 2020 14:06:41 +0200 From: Natanael Copa To: "Alex Xu (Hello71)" Cc: ~alpine/devel@lists.alpinelinux.org Subject: Re: Distro optimization flags Message-ID: <20200707140641.122e8f09@ncopa-desktop.copa.dup.pw> In-Reply-To: <1593625212.dirkptm3b0.none@localhost> References: <1593625212.dirkptm3b0.none.ref@localhost> <1593625212.dirkptm3b0.none@localhost> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-alpine-linux-musl) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi! On Wed, 01 Jul 2020 23:10:30 -0400 "Alex Xu (Hello71)" wrote: > Recently there was some discussion on #alpine-devel about optimization > flags. I think it's worth looking at this issue more closely. > > === Rationale === > > -Os is much slower than -O2. I recompiled gcc 9.3.0-r3 from head with > arguments {3} from below and tested compiling Linux 5.7.7 allnoconfig from > tmpfs on edge with make -j4. On my Intel laptop, edge gcc takes about 45 > seconds, O2 gcc takes 39 seconds, and Debian sid takes only 30 seconds. > On my Ryzen desktop, edge takes 38 seconds, O2 takes 33 seconds, and > Debian takes only 22 seconds. In other words, O2 is about a 15% speedup, > and LTO is another 30-50% on top of that. > > https://lore.kernel.org/lkml/20110323211415.GA8791@elte.hu/ from 2011 > says that the kernel ran 'hackbench 15' 10% faster using -O2. > > http://web.archive.org/web/20200408145313/https://rv8.io/bench from 2017 > appears to say that rv8 ran about 25% faster using -O2 compared to -Os. Thank you for doing those tests. Results are interesting. ... > There is also a third option: we can use -O2 in some common CPU-heavy > programs and libraries, such as gcc and openssl. Alpine already uses > default optimization for musl, which I think works out to -Os for most > components and -O3 for performance-sensitive areas. It would be great if > all packages could do this, but it also sounds like way too much work to > patch every single package (and probably PGO is the right answer there > anyways). We already do this. We set -O2 for zlib for example. ... > == Conclusions == > > Personally, I think a 15% speedup is very much worth a 15% increase in > the small portion of my storage used for storing programs. I definitely > think that the optimization level for gcc itself should be changed, and > building it with LTO should be fixed/implemented as soon as possible. I > certainly hope that nobody is installing gcc on their minimal IoT > systems or whatever that cannot spare 10 MB of space. (Also, those > people are wasting space already on Obj-C and D support.) > > In my opinion, anybody that doesn't want to use an extra few dozen > megabytes of space either should care more about the extra power > consumption, or should be using a custom OpenWRT or Buildroot anyways, > where they can customize everything. I think we should keep -Os as the default and enable -O2 on few packages where it makes sense. Alpine Linux is "Small. Simple. Secure" after all. Those who really want an -O2 distro has a lot of other distros to chose between. That said, I agree that it makes sense to build gcc with -O2. > > [1] https://lists.alpinelinux.org/~alpine/devel/%3C2896c13070c508a49cbaa72c8fb7f34ea947358b.camel%40cogitri.dev%3E > [2] https://github.com/richfelker/mallocng-draft/commit/a9187f0387dcbb77f1f7e4d7774602fd394fb27b > > Cheers, > Alex.