bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

posix_spawn (or vfork) support?


From: Sam James
Subject: posix_spawn (or vfork) support?
Date: Fri, 16 Jun 2023 01:32:33 +0100
User-agent: mu4e 1.10.3; emacs 29.0.91

Hi,

Sorry if this has come up before - I did take a look and couldn't find
anything.

Could bash use posix_spawn/vfork instead of the rather heavyweight
fork?

I'm aware of the work in `devel` to add nofork comsubs which is very
intriguing, but I do wonder about another suggestion: could bash use
posix_spawn (or maybe vfork directly) in some cases?

Recently, we've been optimising a lot of our global-scope (commonly used
bash "libraries") used for packages in Gentoo and unsurprisingly, a lot
of the cost has been down to forks, so this came up.

(It also came up a few years ago in 
https://trofi.github.io/posts/215-perf-and-dwarf-and-fork.html).

Some prior art:
* fish used to do it, but stopped because it didn't make as much sense
for them (fish is for interactive use AFAIK so I guess the environment
size is never big enough for this to pay off): 
https://github.com/fish-shell/fish-shell/issues/3149.

* ksh does it (https://github.com/ksh93/ksh/issues/79).

* The `posixspawn` utility (https://github.com/AlexanderOMara/posixspawn) aims 
to make this
available as a tool to call rather than something builtin.

* https://blog.famzah.net/tag/benchmark-fork/ has an interesting set of
benchmarks.

* https://metacpan.org/pod/Proc::FastSpawn implements this in Perl
with some interesting discussion on the performance benefits.

best,
sam

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]