From: Collin Funk Date: Sat, 28 Feb 2026 06:18:48 +0000 (-0800) Subject: du: avoid locking and flushing standard output X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09a5449ff24d573224b3e857766e87a249f645d6;p=thirdparty%2Fcoreutils.git du: avoid locking and flushing standard output This results in a noticeable increase in performance: $ yes /dev/null | head -n 10000000 | tr '\n' '\0' \ | time --format=%E ./src/du-prev -l --files0-from=- > /dev/null 0:20.40 $ yes /dev/null | head -n 10000000 | tr '\n' '\0' \ | time --format=%E ./src/du -l --files0-from=- > /dev/null 0:16.57 * src/du.c (print_size): Prefer putchar and fputs which may be unlocked unlike printf. Prefer ferror to fflush. --- diff --git a/src/du.c b/src/du.c index 8243ef1ac5..a41ece904a 100644 --- a/src/du.c +++ b/src/du.c @@ -464,10 +464,11 @@ print_size (const struct duinfo *pdui, char const *string) fputs (timetostr (pdui->tmax.tv_sec, buf), stdout); } } - printf ("\t%s%c", string, opt_nul_terminate_output ? '\0' : '\n'); - if (fflush (stdout) != 0) + putchar ('\t'); + fputs (string, stdout); + putchar (opt_nul_terminate_output ? '\0' : '\n'); + if (ferror (stdout)) write_error (); - } /* Fill the di_mnt set with local mount point dev/ino pairs. */