From d833d4689d04183d1dfd1ad862dc80f6f044a41f Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Mon, 16 Nov 2026 16:42:28 +0000 Subject: [PATCH] fs: Optimize filesystem watcher path matching by adding fast path for normalizing path (#66990) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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): Screenshot 2026-11-14 at 20 29 22 **After** (after fast path, see that it only shows that we spend around 900ms normalizing paths for a cargo build now) Screenshot 2026-11-14 at 20 41 25 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. --- crates/fs/src/fs_watcher.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/fs/src/fs_watcher.rs b/crates/fs/src/fs_watcher.rs index bcbbdb63a04..25de8c79d8e 100644 --- a/crates/fs/src/fs_watcher.rs +++ b/crates/fs/src/fs_watcher.rs @@ -570,6 +570,11 @@ impl WatchKey { #[cfg(target_os = "macos")] { use unicode_normalization::UnicodeNormalization as _; + + if lossy.is_ascii() { + return lossy.to_ascii_lowercase(); + } + lossy.chars().nfc().collect::().to_lowercase() }