Self Optimizing Code

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 3 18:54:57 PDT 2016


On Wed, 03 Aug 2016 21:09:46 +0000, ikod wrote:
> This is not just profiling, but "Profile-Guided Optimization (PGO)"

The person is talking about algorithms with tuning parameters (like array 
growth rate when appending) adjusting those parameters based on observed 
characteristics of the program. For instance, if it's observed that 
arrays of a given type tend to grow to ~1800 entries or stay under 100 
entries, the runtime might automatically extend your array from length 
128 to 2048 directly instead of growing to 256, then 512, then 1024, and 
finally 2048.

A compiler would not be allowed to make these changes automatically.

There are significant downsides. You need a lot of bookkeeping to 
determine what values you need. The values are not preserved across runs. 
You need to implement it separately for each algorithm.

You generally only bother when the potential performance gains are great 
as an absolute measure and relative to the amount of bookkeeping you 
would have to do. For instance, with array appending, it's a terribly 
common operation, so you can only use this technique productively if 
gathering the data is dirt cheap.


More information about the Digitalmars-d mailing list