Files
zed/crates
Remco Smits d833d4689d fs: Optimize filesystem watcher path matching by adding fast path for normalizing path (#66990)
## Summary

While I was creating https://github.com/zed-industries/zed/pull/66973 I
still thought that Zed wasn't keeping up at times as fast as I expected,
so I started looking into more in the performance issue and found with
profiling the most time was spend inside the **watcher_ids_covering**
method as you can see inside the profile:

**Before** (before fast path):
<img width="1278" height="465" alt="Screenshot 2026-11-14 at 20 29 22"
src="https://github.com/user-attachments/assets/0f5e5296-7d78-4650-8c0a-5535e62156b8"
/>

**After** (after fast path, see that it only shows that we spend around
900ms normalizing paths for a cargo build now)

<img width="1277" height="462" alt="Screenshot 2026-11-14 at 20 41 25"
src="https://github.com/user-attachments/assets/bfc39454-be94-4b97-a6a1-f55bbd825dee"
/>

My profile shows the following 2 things:

1. We seem to spend alot of time hashing the `WatchKey`.
2. We seem to spend alot of time inside the `folded_path` method to
normalize the path.

The second one is partially addressed in this PR, since most of the time
the path is ASCII case we can just call `to_ascii_lowercase` on the
lossy string. That removes the overhead of looping over every char of
the path, and normalizing it to lowercase.

This reduces the total time spend inside the `watcher_ids_covering`
method by **~31%** (~9s) from **~31.30s** to **~21.50s**.

| Metric | Before fast path | After 1 | After 2 | Average reduction |
|---|---:|---:|---:|---:|
| Notifications received | 213,761 | 214,054 | 213,686 | Comparable
(+0.05%) |
| Average routing/event | 133.4 µs | 90.0 µs | **87.0 µs** | **33.7%** |
| Total routing wall time | 28.51 s | 19.26 s | **18.59 s** | **33.6%**
|
| Total dispatch wall time | 31.32 s | 21.86 s | **21.20 s** | **31.2%**
|
| Observed queue peak | 1,131 | 663 | **359** | 54.8% |
| Average queue wait | 8.20 ms | 4.11 ms | **3.06 ms** | 56.3% |
| Maximum queue wait | 207 ms | 166 ms | **136 ms** | 27.1% |


## Testing

There is already test coverage for normalizing the paths, so didin't add
a test since it feld like adding a test for having a test. but happy to
add a test if thats really wanted!?

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Improved responsiveness during heavy filesystem activity by reducing
filesystem watcher path-matching overhead.
2026-11-16 16:42:28 +00:00
..
…
2026-11-11 19:41:39 +00:00
…
…
…
…
…
…
…
…