This was one optimization from https://github.com/freebsd/freebsd/compare/master...jwroberson:schedlock
It is relatively straightforward in ULE to handle a long set of idle ticks without looping. I did not attempt to do so for 4bsd. This also gives an early return for idlethread because it does not need interactivity or priority adjustments. It does run the percent cpu calculator.