Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,537 Members 49,871 Now Online
XDA Developers Android and Mobile Development Forum

Building with -o3

Tip us?
 
bud77
Old
#1  
bud77's Avatar
Senior Member - OP
Thanks Meter 345
Posts: 866
Join Date: Jun 2011
Location: Near Paris

 
DONATE TO ME
Default Building with -o3

I've read a few things about this option while compiling, but does this have a real difference for building PAC ?

I mean, will there there be any noticeable difference ?
Feeling happy ? There's a thanks button for that
 
Odysseus1962
Old
(Last edited by Odysseus1962; 9th May 2014 at 07:55 PM.)
#2  
Odysseus1962's Avatar
Senior Member
Thanks Meter 447
Posts: 549
Join Date: Sep 2013
Location: Miami
Quote:
Originally Posted by bud77 View Post
I've read a few things about this option while compiling, but does this have a real difference for building PAC ?

I mean, will there there be any noticeable difference ?
I'm a long-time Gentoo Linux user (over 10 years as my primary OS) where every application is compiled from the sources. In the Gentoo installation guide, and on their Wiki the recommended -O optimization is -O2. From the guide located here https://wiki.gentoo.org/wiki/GCC_optimization

"There are seven -O settings: -O0, -O1, -O2, -O3, -Os, -Og, and -Ofast..... With the exception of -O0, the -O settings each activate several additional flags, so be sure to read the GCC manual's chapter on optimization options to learn which flags are activated at each -O level, as well as some explanations as to what they do.

Let's examine each optimization level:

-O0: This level (that's the letter "O" followed by a zero) turns off optimization entirely and is the default if no -O level is specified in CFLAGS or CXXFLAGS. This reduces compilation time and can improve debugging info, but some applications will not work properly without optimization enabled. This option is not recommended except for debugging purposes.

-O1: This is the most basic optimization level. The compiler will try to produce faster, smaller code without taking much compilation time. It's pretty basic, but it should get the job done all the time.

-O2: A step up from -O1. This is the recommended level of optimization unless you have special needs. -O2 will activate a few more flags in addition to the ones activated by -O1. With -O2, the compiler will attempt to increase code performance without compromising on size, and without taking too much compilation time.

-O3: This is the highest level of optimization possible. It enables optimizations that are expensive in terms of compile time and memory usage. Compiling with -O3 is not a guaranteed way to improve performance, and in fact in many cases can slow down a system due to larger binaries and increased memory usage. -O3 is also known to break several packages. Therefore, using -O3 is not recommended.

-Os: This option will optimize your code for size. It activates all -O2 options that don't increase the size of the generated code. It can be useful for machines that have extremely limited disk storage space and/or have CPUs with small cache sizes.

-Og: In GCC 4.8, a new general optimization level, -Og, has been introduced. It addresses the need for fast compilation and a superior debugging experience while providing a reasonable level of runtime performance. Overall experience for development should be better than the default optimization level -O0. Note that -Og does not imply -g, it simply disables optimizations that may interfere with debugging.

-Ofast: New in GCC 4.7, consists of -O3 plus -ffast-math, -fno-protect-parens, and -fstack-arrays. This option breaks strict standards compliance, and is not recommended for use.

As previously mentioned, -O2 is the recommended optimization level. If package compilation fails and you aren't using -O2, try rebuilding with that option. As a fallback option, try setting your CFLAGS and CXXFLAGS to a lower optimization level, such as -O1 or even -O0 -g2 -ggdb (for error reporting and checking for possible problems)."

As you can see -O2 is the recommended optimization level and is what I use in my systems. In fact, if you compile with -O3 and have an issue Gentoo won't accept your bug report until you've gone back and recompiled with -O2 or lower optimization first. Compiling with -O3 has long been known to be problematic. The resulting binaries tend to be considerably larger (not desirable on memory limited devices like phones) and often behave in unexpected ways.

Google is your friend, there is much info regarding this on the net. The more you look at it the more you'll find that the consensus is that the best combination of binary speed, size and stability is usually achieved with -O2 or -Os optimization.
Current device: LG G2 (D801)
ROM: CloudyStock 2.5 KK-4.4.2 - Cloudyfa.
Kernel: SimpleKernel v6 - dr87.

Previous device: HTC Amaze 4G
Final ROM: CM-10 - Compiled and customized by me
To whoever stole it: What goes around comes around!

Previous device: HTC HD2 (TMOUS - LEO1024)
Final ROM: NexusHD2-JellyBean-CM10.1.3 v2.7 - Tytung
Had more lives than a cat
Lesson: If it ain't broke, don't fix it!
RIP
The Following 3 Users Say Thank You to Odysseus1962 For This Useful Post: [ Click to Expand ]
 
bud77
Old
#3  
bud77's Avatar
Senior Member - OP
Thanks Meter 345
Posts: 866
Join Date: Jun 2011
Location: Near Paris

 
DONATE TO ME
Thanks, but I alread read such things

My question was wether there was a real gain rom in building with o3

Anyway, I tried and installed it, and it's running fine for the past 2 days now
But no noticeable difference
Feeling happy ? There's a thanks button for that
 
Odysseus1962
Old
(Last edited by Odysseus1962; 10th May 2014 at 03:29 AM.)
#4  
Odysseus1962's Avatar
Senior Member
Thanks Meter 447
Posts: 549
Join Date: Sep 2013
Location: Miami
Quote:
Originally Posted by bud77 View Post
Thanks, but I alread read such things

My question was wether there was a real gain rom in building with o3

Anyway, I tried and installed it, and it's running fine for the past 2 days now
But no noticeable difference
I understood what your question was, and believed I gave a thorough answer. In most mobile devices which are generally RAM starved, have small caches and lack storage capacity, whatever little bit you might gain in speed via -O3 optimization is lost because the binaries are considerably larger. The unwanted cache thrashing alone probably counters whatever performance gain is made in optimization. And because these binaries sometimes exhibit unexpected behavior, there's a possibility of introducing unwanted instability. These affects are well known and why I chose to compile my ROM(s) with -Os or -O2.
Current device: LG G2 (D801)
ROM: CloudyStock 2.5 KK-4.4.2 - Cloudyfa.
Kernel: SimpleKernel v6 - dr87.

Previous device: HTC Amaze 4G
Final ROM: CM-10 - Compiled and customized by me
To whoever stole it: What goes around comes around!

Previous device: HTC HD2 (TMOUS - LEO1024)
Final ROM: NexusHD2-JellyBean-CM10.1.3 v2.7 - Tytung
Had more lives than a cat
Lesson: If it ain't broke, don't fix it!
RIP
The Following User Says Thank You to Odysseus1962 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes