'Why are pipes in bash 5.05 so slow?

I'm running a bash script that makes extensively use of piping. In bash version 5.0.17 (running in Ubuntu 20.04.4) the script is really slow. I did some simple test and I found odd results:

$ bash-5.0$ time for i in {1..10000}; do echo > /dev/null | echo > /dev/null  ; done

real    0m21.716s
user    0m25.496s
sys 0m14.913s

Removing the pipe:

bash-5.0$ time for i in {1..10000}; do echo > /dev/null ; echo > /dev/null  ; done

real    0m0.097s
user    0m0.071s
sys 0m0.026s

With other bash version I got different (best) results:

bash-5.1$ time for i in {1..10000}; do echo > /dev/null | echo > /dev/null  ; done

real    0m10.255s
user    0m9.366s
sys 0m7.084s

With bash 4.4:

bash-4.4$ time for i in {1..10000}; do echo > /dev/null | echo >/dev/null ; done

real    0m9.620s
user    0m5.010s
sys 0m7.528s

Any idea why the pipe behaves so badly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source