This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Impact of GCC optimizations on resource consumption


On 10/09/2015 06:03 PM, Mohamed Boussaa wrote:
> Hi all,
> 
> I am studying the impact of GCC optimization options on CPU & memory
> consumption of compiled programs.
> 
> Executing code compiled with O3 is it always so greedy in term of resources ?
> 
Not sure, what you mean by that. Memory consumption of a program is
determined by:
1. Size of the binary (it is studied and monitored, as you mentioned)
2. Size of data segment (variables with static storage duration).
Optimizers can throw away some unused variables (i.e. decrease memory
consumption, but not increase).
3. Size of the stack. Probably inlining can affect it, but typically
stack memory is rather limited anyway (for example on my x86_64 Debian 7
box the default limit is only 8 MB per process). The situation is
probably a bit different for programs written in Fortran (at least, SPEC
benchmarks require increased stack size for Fortran benchmarks).
Probably our Fortran frontend developers could give more detailed
comments here, if you are interested in this particular case.
4. At last, IMHO, the most important part: dynamically allocated memory
(heap). FWIW, allocation and deallocation is considered to be observable
behavior. This means that optimizations must not change it.

As for CPU usage, it is determined by interleaved periods of waits (i.e.
waiting for I/O completion, waiting on synchronization primitives, e.g.
mutexes) and periods of CPU utilization. The compiler cannot affect how
fast your program will read the file from disk, but it can make your
program process this file faster. Again, why should CPU usage increase
in this case?

Could you give some concrete examples in which resource consumption
increases in a better optimized program?

-- 
Regards,
    Mikhail Maltsev


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]