On Mon, Mar 25, 2019 at 11:38:41AM +0100, SZEDER Gábor wrote:

> diff --git a/progress.c b/progress.c
> index 02a20e7d58..b57c0dae16 100644
> --- a/progress.c
> +++ b/progress.c
> @@ -86,28 +86,30 @@ static void display(struct progress *progress, uint64_t 
> n, const char *done)
>               return;
>  
>       progress->last_value = n;
> +
> +     if (!is_foreground_fd(fileno(stderr)) && !done) {
> +             progress_update = 0;
> +             return;
> +     }
> +

Moving it here causes a measurable slowdown for:

  git rev-list --progress=foo --objects --all

This function gets called for every single increment of the progress
counter. Whereas in its old location:

>       tp = (progress->throughput) ? progress->throughput->display.buf : "";
>       eol = done ? done : "   \r";
>       if (progress->total) {
>               unsigned percent = n * 100 / progress->total;
>               if (percent != progress->last_percent || progress_update) {
>                       progress->last_percent = percent;
> -                     if (is_foreground_fd(fileno(stderr)) || done) {
> -                             fprintf(stderr, "%s: %3u%% 
> (%"PRIuMAX"/%"PRIuMAX")%s%s",
> -                                     progress->title, percent,
> -                                     (uintmax_t)n, 
> (uintmax_t)progress->total,
> -                                     tp, eol);
> -                             fflush(stderr);
> -                     }

It was only triggered when we accumulated enough increments to print. So
we save a few instructions in the backgrounded case, but it costs us a
lot of extra syscalls in every other case.

According to "strace -c", the number of ioctls for that rev-list on
git.git went from 6 to 373,461. But more importantly, my best-of-five
timings went from 3.340s from 3.407s. That's only 2%, but it would be
nice not to pay it if we don't need to.

-Peff

Reply via email to