Monday 26 December 2011

Articles on Programming Optimisation

I've linked below some great articles on optimisation. Some of the later ones are quite low level and more just points of interest rather than proving especially useful these days, at least for my purposes.

Some key rules to follow
http://assemblyrequired.crashworks.org/2008/12/22/ea-stl-prevents-memory-leaks/#more-92

Lots of general tips and great blog
http://assemblyrequired.crashworks.org/category/programming/

Good one on branching and data layout for game systems/containers again
http://altdevblogaday.com/2011/11/10/optimisation_lessons/

Optimizing for cache coherence – excellent, and a good reminder of why thinking about the data flow in a program is so important.
http://supercomputingblog.com/optimization/taking-advantage-of-cache-coherence-in-your-programs/

From:
http://gamedev.stackexchange.com/questions/853/c-low-level-optimization-tips

A very, very low-level tip, but one that can come in handy:

Most compilers support some form of explicit conditional hinting. GCC has a function called __builtin_expect which lets you inform the compiler what the value of a result probably is. GCC can use that data to optimize conditionals to perform as quickly as possible in the expected case, with slightly slower execution in the unexpected case.

if(__builtin_expect(entity->extremely_unlikely_flag, 0)) {
// code that is rarely run
}
I've seen a 10-20% speedup with proper use of this.

http://gamesfromwithin.com/data-oriented-design

Use const when possible – it can make the compiler optimise things.

http://diaryofagraphicsprogrammer.blogspot.com/2008/11/iphone-arm-vfp-code.html

_restrict keyword for telling the compiler pointers won’t alias (one pointer -> one instance of data ratio)
http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html

:? Sometimes compiles to be faster than if else
http://assemblyrequired.crashworks.org/2009/01/04/fcmp-conditional-moves-for-branchless-math/

purecall and virtual function overhead
http://thetweaker.wordpress.com/2010/06/03/on-_purecall-and-the-overheads-of-virtual-functions/

No comments:

Post a Comment