performance – What optimization strategies for C programs can be applied to what kinds of other languages?


In Chapter 5 in Computer Systems: a Programmer’s Perspective (3ed 2015):

We have described a number of basic strategies for optimizing program performance:

  1. Basic coding principles. Avoid optimization blockers so that a compiler can generate efficient code.

    • Eliminate excessive function
      calls. Move computations out of loops when possible. Consider
      selective compromises of program modularity to gain greater
      efficiency.

    • Eliminate
      unnecessary memory references. Introduce temporary variables to hold
      intermediate results. Store a result in an array or global variable
      only when the final value has been computed.

  2. Low-level optimizations. Structure code to take advantage of the hardware capabilities.

    • Unroll loops to reduce overhead and to enable
      further optimizations.

    • Find ways to increase instruction-level
      parallelism by techniques such as multiple accumulators and
      reassociation.

    • Rewrite conditional operations in a functional style to
      enable compilation via conditional data transfers. A final 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.)

Thanks.