Hubbry Logo
search
logo

Peephole optimization

logo
Community Hub0 Subscribers
Write something...
Be the first to start a discussion here.
Be the first to start a discussion here.
See all
Peephole optimization

Peephole optimization is an optimization technique performed on a small set of compiler-generated instructions, known as a peephole or window, that involves replacing the instructions with a logically equivalent set that has better performance.

For example:

The term peephole optimization was introduced by William Marshall McKeeman in 1965.

Peephole optimization replacements include but are not limited to:

Modern compilers often implement peephole optimizations with a pattern-matching algorithm.

The following Java bytecode:

can be replaced with the following, which executes faster:

As for most peephole optimizations, this is based on the relative efficiency of different instructions. In this case, dup (which duplicates and pushes the top of the stack) is known/assumed to be more efficient than aload (which loads a local variable and pushes it onto the stack).

See all
User Avatar
No comments yet.