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-09-11 09:13:44 +00:00
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.6 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%