[illumos] attempt to use posix_spawn to spawn processes

illumos has `posix_spawn`, and the very newest versions also have `_addchdir`,
so use that.

This is a nice ~4x performance improvement for process creation. My go-to as
usual is nextest against the clap repo, which acts as a stress test for process
creation -- with [this commit]:

```console
$ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)'
before: Summary [   1.747s] 879 tests run: 879 passed, 2 skipped
after:  Summary [   0.445s] 879 tests run: 879 passed, 2 skipped
```

[this commit]: fde45f9aea
This commit is contained in:
Rain
2025-02-11 22:50:26 +00:00
parent bca5f37cbd
commit b340545114
3 changed files with 19 additions and 4 deletions

View File

@@ -410,6 +410,7 @@ impl Command {
#[cfg(not(any(
target_os = "freebsd",
target_os = "illumos",
all(target_os = "linux", target_env = "gnu"),
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
@@ -427,6 +428,7 @@ impl Command {
// directly.
#[cfg(any(
target_os = "freebsd",
target_os = "illumos",
all(target_os = "linux", target_env = "gnu"),
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
@@ -584,6 +586,10 @@ impl Command {
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
use crate::sys::weak::weak;
// POSIX.1-2024 standardizes this function:
// https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_addchdir.html.
// The _np version is more widely available, though, so try that first.
weak! {
fn posix_spawn_file_actions_addchdir_np(
*mut libc::posix_spawn_file_actions_t,
@@ -591,7 +597,16 @@ impl Command {
) -> libc::c_int
}
posix_spawn_file_actions_addchdir_np.get()
weak! {
fn posix_spawn_file_actions_addchdir(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char
) -> libc::c_int
}
posix_spawn_file_actions_addchdir_np
.get()
.or_else(|| posix_spawn_file_actions_addchdir.get())
}
/// Get the function pointer for adding a chdir action to a