Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's C++ optimization & Whole program optimizatoin in visual studio [closed]

Essentially I want to know what's c++ optimization (/O) & Whole program optimization (/GL) is all about.

Would appreciate deep explanation.

C++ optimizatoin

Whole Program Optimization

Thanks

like image 779
RoundPi Avatar asked Dec 18 '12 17:12

RoundPi


1 Answers

MSVC is a so-called Optimizing Compiler. OCs take the code that you have written and re-write parts of it in order to minimize the memory footprint, maximize execution speed, or both. They do this by leveraging deeply technical knowledge of the platform that the code is to be run on, generally targeting specific instruction set.

OCs such as MSVC, GCC, LLVM and many others all utilize many different techniques to accomplish this. The techniques themselves are way beyond the scope of what can be explained in an internet post, even if I knew them all (which I don't). But there are some things that you should keep in mind.

A program that has been optimized is much more difficult to debug than one that has not been. A lot of code might have been moved in terms of both order of execution and locality within the program, and symbols are stripped away.

In general, the Standard allows a compiler to make any change to your program it wishes, so long as the observable behavior of your program is the same "AS-IF" no changes had been made.

The parts of the compiler that are responsible for optimizing your code have been designed and written by dedicated teams of very smart people over many years. The end result is a compiler that, by and large, is far better at optimizing your code than you could ever hope to be. As a rule, it is pointless to try to implement your own micro-optimizations for two reasons. One, the compiler can generally do a better job, and two, micro-optimizations you write will confound the compiler in its ability to implement its own optimizations. By micro-optimizing your code by hand, you might actually make your program perform worse.

like image 189
John Dibling Avatar answered Oct 12 '22 13:10

John Dibling