perf: reduce loop count when calculating priority