optimize history while drawing