# fs: Coalesce queued rescans after watcher overflow \(\#60098\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f8e1ab7f3c92ef94ffd563c62cdcb867fb9d55a3

Requested commit: f8e1ab7f3c92ef94ffd563c62cdcb867fb9d55a3

Commit: f8e1ab7f3c92ef94ffd563c62cdcb867fb9d55a3

Tree: 4562f96ae59bbf652807fe8ec97cd6e7371c5212

Author: Anthony Eid

Committer: GitHub

## Message

```
fs: Coalesce queued rescans after watcher overflow (#60098)

After a filesystem watcher loses sync (e.g. a `git pull` that changes
many files overflows the backend's event queue), the backend can enqueue
many `Rescan` markers in quick succession. The dispatch thread processed
each one separately, and each rescan invokes every registration for that
watcher mode, so a single burst could kick off several full worktree
scans at once — leading to sustained CPU and an unresponsive project
panel.

This adds `dispatch_batch`, which handles the first event and drains the
events already waiting in the channel, forwarding at most one `Rescan`
per `WatcherMode` per drained batch while letting ordinary filesystem
events and errors pass through untouched. A later watcher overflow can
still trigger another recovery scan.

Reported with a reproduction and patch in #59610.

Release Notes:

- Batch file watcher rescan events to improve Zed's responsiveness under
heavy FS usage
```

## Parents

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

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