# fs: Dispatch watcher events from the reader thread to avoid thrashing \(\#59537\) · gitcafe/zed

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

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

Visibility: public

Requested revision: a0e37126e9456da0f6855cbfb202fa4efead6fec

Requested commit: a0e37126e9456da0f6855cbfb202fa4efead6fec

Commit: a0e37126e9456da0f6855cbfb202fa4efead6fec

Tree: 221b2fc07b64bda5cb1d54964fa713733b20e8f9

Author: Neel

Committer: GitHub

## Message

```
fs: Dispatch watcher events from the reader thread to avoid thrashing (#59537)

On large worktrees, normal fs activity (like a `git checkout`) could
send the file watcher in to a rescan thrash: we processed each event on
the thread that reads events from the OS, and each event was checked
against every watched directory. On big projects this was too slow to
keep up, so the OS event buffer overflowed and dropped events, and a
dropped event forces a full rescan - creating this unbounded loop.

This PR moves dispatch onto a dedicated `fs-watcher-dispatch` thread.
The reading thread now only drops `Access` events and forwards the rest,
so it should stay fast enough to keep draining the kernel queue and
bursty fs behaviour won't cause an overflow.

In addition, we now index registrations by watched path. Instead of
waking up every watched folder whenever any file changes anywhere, we
now only wake up the folders that actually contain the changed file.

Closes FR-31. Related to #57042.

Release Notes:

- Improved file watcher performance on large worktrees
```

## Parents

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

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