Fix a massive inefficiency in the sort fun

We were rebuilding the current shard map on every invocation of the sort
fun instead of building a sort fun that pulls it in via the closure.