Bash makes many calls to stdio functions that may have unlocked_stdio(3)
equivalents. Since the locking functionality provided by the regular
versions is only useful in multi-threaded applications, it probably makes
sense for Bash to use the *_unlocked versions where available.

E.g. in situations where execution time is dominated by putchar(3) calls,
using putchar_unlocked(3) can offer an ~2X speedup:

    $ fun() { printf -v X "%$((1<<24))s" && time printf "$X"; }
    $ export -f fun

    $ bash.old -c fun >/dev/null
    real    0m0.720s
    user    0m0.669s
    sys     0m0.048s
    $ bash.new -c fun >/dev/null
    real    0m0.370s
    user    0m0.301s
    sys     0m0.067s

This patch is basically an adoption of the unlocked-io module from Gnulib.

Attachment: 0001-use-unlocked-stdio-functions.patch
Description: Binary data

Reply via email to