Added optimizer interface to optimize for the current activity.
Modifications throughout the optimizer stack.