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
any reason to declare this `val` only to return it, instead of just returning it?