Use tsort for topological sorting (massive speedup)

This provides a massive speed-up to dependency ordering. In a test with a manifest with 672 files, the improvement was 3,659x.

(cc @lopatin)