Skip to content

util: Always use posix_spawn on macOS even with pre_exec hooks#49090

Merged
kubkon merged 4 commits intomainfrom
kubkon/fix-child-spawn-macos
Feb 13, 2026
Merged

util: Always use posix_spawn on macOS even with pre_exec hooks#49090
kubkon merged 4 commits intomainfrom
kubkon/fix-child-spawn-macos

Conversation

@kubkon
Copy link
Member

@kubkon kubkon commented Feb 13, 2026

Here's some backstory:

  • on macOS, @cole-miller and I noticed that since roughly Oct 2025, due to some changes to latest macOS Tahoe, for any spawned child process we needed to reset Mach exception ports (LSPs no longer working (macOS 26 Tahoe) #36754 + RemiKalbe@6e8f2d2)
  • the changes in that PR achieve that via pre_exec hook on std::process::Command which then abandons posix_spawn syscall for fork + execve dance on macOS (we tracked it down in Rust's std implementation)
  • as it turns out, fork + execve is pretty expensive on macOS (apparently way more so than on other OSes like Linux) and fork takes a process-wide lock on the allocator which is bad
  • however, since we wanna reset exception ports on the child, the only official way supported by Rust's std is to use pre_exec hook
  • posix_spawn on macOS exposes this tho via a macOS specific extension to that syscall posix_spawnattr_setexceptionports_np but there is no way to use that via any standard interfaces in std::process::Command
  • thus, it seemed like a good idea to instead create our own custom Command wrapper that on non-macOS hosts is a zero-cost wrapper of smol::process::Command, while on macOS we reimplement the minimum to achieve smol::process::Command  with posix_spawn under-the-hood

Notably, this changeset improves git-blame in very large repos significantly.

Release Notes:

  • Fixed performance spawning child processes on macOS by always forcing posix_spawn no matter what.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 13, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 13, 2026
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Feb 13, 2026

Messages
📖

This PR includes links to the following GitHub Issues: #36754
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against 48b22cc

@kubkon kubkon force-pushed the kubkon/fix-child-spawn-macos branch from b250a84 to a22f0e6 Compare February 13, 2026 10:00
@kubkon kubkon force-pushed the kubkon/fix-child-spawn-macos branch 2 times, most recently from f41af35 to 4823a99 Compare February 13, 2026 12:10
@kubkon kubkon force-pushed the kubkon/fix-child-spawn-macos branch from 4823a99 to 48b22cc Compare February 13, 2026 15:08
@kubkon kubkon merged commit 16dfc60 into main Feb 13, 2026
27 checks passed
@kubkon kubkon deleted the kubkon/fix-child-spawn-macos branch February 13, 2026 19:16
cole-miller added a commit that referenced this pull request Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants