Maybe a program can change itself to be better. This concerns runtime rather than compile time optimization in Compiler Optimizations which are usually permanent.

The first way we optimize runtime is with the Cache. However, your program should already be doing this.

Observe and Change

Your programs configuration changes at runtime to adapt to observed behaviour. This works because our initial guess might not be correct and conditions can change at runtime. Some examples include:

  • Remembering efficient ways to run complex queries
  • A server updating how it stores data based on usage (I assume optimizing for reads and writes using Database data structures)
  • Invocation of external services (using Content Delivery Networks) etc.

Genetic Algorithms

See Genetic Algorithms.

Runtime Optimization (JIT)

  • Escape Analysis
  • On-Stack Replacement
  • JIT Intrinsic In terms of Rust, we don’t have this option but we could have different versions of code and swap them in as needed. That means we need to prepare them in advance and swap in at runtime. Also don’t write a specific compiler for a program lol.

Warning

Programs that rewrite themselves are judged as suspicious by anti-virus software. This software may affect the end user experience.