In Chapter 5 in Computer Systems: a Programmer’s Perspective (3ed 2015):
We have described a number of basic strategies for optimizing program performance:
Basic coding principles. Avoid optimization blockers so that a compiler can generate efﬁcient code.
Eliminate excessive function
calls. Move computations out of loops when possible. Consider
selective compromises of program modularity to gain greater
unnecessary memory references. Introduce temporary variables to hold
intermediate results. Store a result in an array or global variable
only when the ﬁnal value has been computed.
Low-level optimizations. Structure code to take advantage of the hardware capabilities.
Unroll loops to reduce overhead and to enable
Find ways to increase instruction-level
parallelism by techniques such as multiple accumulators and
Rewrite conditional operations in a functional style to
enable compilation via conditional data transfers. A ﬁnal word of
advice to the reader is to be vigilant.
The book applies the above optimization strategies to writing efficient programs in C with the help of C compilers. The first group is hardware-independent strategies and the second is hardware dependent.
I wonder if the strategies can be applied to writing programs in other languages?
- What kinds of strategies can, and what can’t?
- What kinds of languages can the strategies be applied to? (Especially high level programming languages of various paradigms: Java, C#, Scala, Haskell, Python, Scheme.)