Optimize sync_all

This commit stores the environments read by reading the top file in
__context__ so that the top file does not need to be read once for each
sync doing in salt.modules.saltutil.sync_all().
Sync custom types before executing highstate
Avoid UnboundLocalError when there is no top file
More optimizations in HighState class

We already have load_dynamic() which runs a sync_all, I didn't catch this
in my previous commits. Also, load_dynamic() refreshes the modules
twice, once by calling the sync_all with no refresh argument (the
function defaults to refresh=True), and once by invoking
self.state.module_refresh() before the function exits. Passing
refresh=False removes one of the module refreshes, which should speed
things up a little more.
Merge pull request #13011 from terminalmage/issue9730

Optimizations for saltutil.sync_all and state.highstate