RFC: optimize migration optimizer loop

Previously, the optimizer started over from the beginning whenever it optimized something. This can be optimized by skipping all the unchanged operations before the modified one. 
Example:

A, B, C, D

Assume C and D have been merged into E:

A, B, E

Then it's not necessary to try to reduce A and B again, instead one can start with A and E.

**The RFC part:** My implementation doesn't seem to be fully correct. Without the additional reduce method, a test fails.