# Move the crash handler process spawn to a background thread \(\#58881\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/253606e8e0396da2d6897c1eb996ea92aece23c4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 253606e8e0396da2d6897c1eb996ea92aece23c4

Requested commit: 253606e8e0396da2d6897c1eb996ea92aece23c4

Commit: 253606e8e0396da2d6897c1eb996ea92aece23c4

Tree: ab822d55a93ea7c50fc00a4f97ee25985a9fbc37

Author: Anthony Eid

Committer: GitHub

## Message

```
Move the crash handler process spawn to a background thread (#58881)

Moves the crash handler subprocess spawn off the main thread to speed up
startup, especially on Windows where process creation is slower.

Previously `crashes::init` did part of its work synchronously when it
was *called*, including `spawn_crash_handler`, which launches the `zed
--crash-handler` child process (a synchronous `CreateProcessW` on
Windows). Because `init` is evaluated inline as the argument to
`background_executor().spawn(crashes::init(...))` in `main.rs`, that
subprocess spawn ran on the main thread during startup rather than on
the executor.

This PR makes `connect_and_keepalive` a fully `async fn`, so all of that
work, including the subprocess spawn, now runs on the background
executor instead of blocking the main thread.

I don't have a Windows machine to capture before/after numbers, but the
crash handler spawn is clearly on the startup critical path. Logs in the
Windows slow startup reports show it taking ~100–700ms between `spawning
crash handler process` and `connected to crash handler process` (e.g.
#40621, #54856), all of which previously blocked the main thread.

Related to #49442

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Improved startup performance
```

## Parents

- [a225d510243a6a8af5019c80104f93ee99b67e78](https://git.cafe/gitcafe/zed/commit/a225d510243a6a8af5019c80104f93ee99b67e78?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/253606e8e0396da2d6897c1eb996ea92aece23c4?format=markdown)
