optimize recurrent computation