chainlint.pl: do not spawn more threads than we have scripts
commitd558509e2527abaf0faf1f93cad775eeeada0d17
authorJeff King <peff@peff.net>
Wed, 10 Jul 2024 08:35:57 +0000 (10 04:35 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Jul 2024 17:14:21 +0000 (10 10:14 -0700)
tree759ec94e4baa47ccea677d1f33919a258ccf28c1
parenta7c1c102562c141b752f06f94c99438fa80319e8
chainlint.pl: do not spawn more threads than we have scripts

The chainlint.pl script spawns worker threads to check many scripts in
parallel. This is good if you feed it a lot of scripts. But if you give
it few (or one), then the overhead of spawning the threads dominates. We
can easily notice that we have fewer scripts than threads and scale back
as appropriate.

This patch reduces the time to run:

  time for i in chainlint/*.test; do
perl chainlint.pl $i
  done >/dev/null

on my system from ~4.1s to ~1.1s, where I have 8+8 cores.

As with the previous patch, this isn't the usual way we run chainlint
(we feed many scripts at once, which is why it supports threading in the
first place). So this won't make a big difference in the real world, but
it may help us out in the future, and it makes experimenting with and
debugging the chainlint tests a bit more pleasant.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/chainlint.pl