Introduction[]
This page aims to be a comprehensive catalog of code optimizations similar to the catalog of refactorings in Martin Fowler's "Refactoring book", or the Portland's Patterns Repository.
The Catalog[]
- Optimization - Caching - Caching or memoization of data in a place where it can be looked up faster.
- See the Schwartzian Transform for optimising sorting.
- Optimization - Changing Dependencies - Switching to a more performant dependency (a faster language, database, library, etc.)
- Optimization - CPU Cache Optimization - Cache oblivious algorithms, cache optimising algorithms, etc.
- Optimization - Extracting a Function - the opposite of inlining. May optimise a little by reducing memory consumption.
- Optimization - Inlining a Function
- Optimization - Introducing Indirection - e.g: in C, etc. using an array to pointers of structs instead of a vector of structs.
- Optimization - More Efficient Lookup
- Optimization - Reordering Struct Members
- Optimization - Reducing Memory Consumption - less memory usage → less cache misses and more data fit in one cache line.
- An array of pointers instead of a direct vector of structs.
- Optimization - Schlemiel the Painter - see Joel on Software's "Back to Basics" article.
- Optimization - Using Bitwise Operations
- Optimization - Working in a Different Encoding - UTF-8 and other encodings can cause a significant slowdown in the processing, so it can be faster using a different encoding. (see the "LC_ALL=C" trick in the Unix shell).
Philosophy[]
Implications of Optimization[]
- Code may be harder to understand.
- Lack of modularity.
- Added Complexity.
- libJudy (faster) vs. libavl2 (smaller and simpler).
- Freecell Solver (faster and more powerful) vs. patsolve (smaller)