Does profile-optimized compilation done by the compiler greatly exacerbate cases that are not covered by the profiling dataset?

This question is not specific to C ++, AFAIK will determine runtime, such as Java RE, which can optimize profiled optimization on the fly. I'm interested too.

MSDN describes PGO as follows:

  • I use my program and run it under the profiler, then
  • the compiler uses the data collected by the profiler to automatically reorganize branches and loops in such a way that incorrect branch prediction is reduced and most often the code is compact to improve its locality.

Now, obviously, the result of profiling will depend on the data set used.

With the usual manual profiling and optimization, I would find some bottlenecks and improve these bottlenecks and probably leave all the other code intact. PGO seems to improve frequently-executed code by reducing code execution time less.

Now, what if this slow-motion code often runs in a different dataset that the program sees in the real world? Will the performance of a program deteriorate compared to a program compiled without PGO, and how bad will the likelihood of degradation be? In other words, does PGO really improve my code performance for the profiling dataset and possibly degrade it for other datasets? Are there real examples with real data?

+5
2

: PGO, , . "-PGO" . TL; DR .

, PGO. ( ):

. , A, B, B , B A.

. .

. , , , .

, -, , . - .


. , , (). , .

. / , , , , .

. , , , . .

EH. EH-, , , , .

. , , , - L1 (, , thrashes L2). , PGO:)

- - .

, .


/ - , , .

, " , ( , ). , - - - - . , , . (" " ).


. , switch , . switch. if/else, if/else, if else, , .

" ", PGO.

, , / , .

:

if (x > 0) DoThis() else DoThat();

x > 0.


Intrinsics . , , . .

, .

: - " ", , .

, memmove, 16 .

MOV , memmove ( , ) , .

, , , , /.

, : PGO memmove, nline memmove. ( ) - , 10% . 10% - .

, , L1

, , . , , . , , - .


:

  • .
  • , .
  • ,
  • , , .
  • ( , ) , - ,

,

  • , ,
  • PGO.

/ PGO, PGO.

+9

PGO, , , . /, , , .

, . . PGO, , .

, , , . , , , PGO. , , .

0

All Articles