Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

profile-guided optimization (C)

Anyone know this compiler feature? It seems GCC support that. How does it work? What is the potential gain? In which case it's good? Inner loops?

(this question is specific, not about optimization in general, thanks)

like image 769
elmarco Avatar asked Sep 09 '08 18:09

elmarco


2 Answers

It works by placing extra code to count the number of times each codepath is taken. When you compile a second time the compiler uses the knowledge gained about execution of your program that it could only guess at before. There are a couple things PGO can work toward:

  • Deciding which functions should be inlined or not depending on how often they are called.
  • Deciding how to place hints about which branch of an "if" statement should be predicted on based on the percentage of calls going one way or the other.
  • Deciding how to optimize loops based on how many iterations get taken each time that loop is called.

You never really know how much these things can help until you test it.

like image 82
Greg Rogers Avatar answered Oct 04 '22 09:10

Greg Rogers


PGO gives about a 5% speed boost when compiling x264, the project I work on, and we have a built-in system for it (make fprofiled). Its a nice free speed boost in some cases, and probably helps more in applications that, unlike x264, are less made up of handwritten assembly.

like image 20
Dark Shikari Avatar answered Oct 04 '22 08:10

Dark Shikari