Change task depth count to use countbyvalue

This generally works better when the parallelism flag value is fairly high (> 10k) while the older method would take 3-4 min on the same datasets