Skip to content

Prefer posix_spawn on apple targets #126097

@adamsitnik

Description

@adamsitnik
  • The only way to limit handle inheritance in performant way on apple targets is to use POSIX_SPAWN_CLOEXEC_DEFAULT supported by posix_spawn. So it's a must have for Make Process.Start have a option to change handle inheritance #13943.
  • It would allow us to support Process APIs on iOS. The only unclear part is testing.
  • It's the recommended and most performant way to spawn processes on Apple targets. The numbers I got for Prefer posix_spawn on OSX #126063 show even up to x100 boost on arm64 and x5 on x64.
  • We can't take for granted that it would just work on all the platforms. For example in Don't use vfork on android #118085, we had to switch to fork (from vfork) on Android. However, it's worth just asking Copilot to write a prototype and use EgorBot to run some simple benchmarks on Linux x64 and arm64. We should benchmark various scenarios that would include processes that are cheap and expensive to copy . Check https://rust-lang.github.io/rfcs//3228-process-process_group.html for rust approached it.
  • We still need a fallback to fork/exec to support setguid, setuid and groups:

if (setCredentials)
{
if (SetGroups(groups, groupsLength, getGroupsBuffer) == -1 ||
setgid(groupId) == -1 ||
setuid(userId) == -1)
{
ExitChild(waitForChildToExecPipe[WRITE_END_OF_PIPE], errno);
}
}

cc @jkotas @stephentoub @tmds

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions