Re: Performance regression in 5.x: fork-heavy $() loops slow down ~2.5x on second run when built with --with-bash-malloc=no
Chet Ramey <[email protected]> Fri, 15 May 2026 10:11:58 -0400
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Organization | ITS, Case Western Reserve University |
| Message-ID | <[email protected]> |
On 5/13/26 11:53 PM, debianyu wrote:
> In an interactive shell, executing a fork-heavy loop with command substitution twice consecutively exhibits a ~2.5x slowdown on the second and subsequent runs:
>
> time for i in {1..10000}; do echo $(date) >/dev/null; done # ~16s
> time for i in {1..10000}; do echo $(date) >/dev/null; done # ~40s
> time for i in {1..10000}; do echo $(date) >/dev/null; done # ~40s
>
> The slowdown persists for the shell's lifetime, including subshells spawned from it.
>
> Bisecting build configurations and bash versions reveals the slowdown requires both:
>
> Bash 5.x series (5.0 onward; 4.4 unaffected)
> ./configure --with-bash-malloc=no (bash uses glibc malloc)
>
> Either condition alone does not trigger the issue:
That's interesting. I haven't seen the glibc malloc trigger such a dramatic
slowdown before.
> Trigger Condition: Loop body must involve both fork and execve. Builtins or fork-only operations (e.g., x=$(:)) do not trigger the issue.
I agree that the patch in
https://lists.gnu.org/archive/html/bug-bash/2026-05/msg00038.html
is worth looking at.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
(application/pgp-signature, 203 B)
-----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQR8ATX7CIqvbGbGULm7WGnwZOp0qwUCagcprgUDAAAAAAAKCRC7WGnwZOp0q9jc AJ92tDe8gcEruJ9ht6YADc2GlFGBUQCfQRmKvXE9hklkjIOpZJS9j9kUX8g= =pQXF -----END PGP SIGNATURE-----