cache the dispatch table on the depth first visitor

We know the API for the depth first visitor in advance, so it's OK to
calcuate this cache in advance