optimizer prewalk/postwalk impl