introduce a transition cache to avoid recomputing every time.