Emit less update events for odd FS events (#39557)
When running flycheck, I've noticed that scrolling starts to lag: https://github.com/user-attachments/assets/b0bef0a3-ccbd-479d-a385-273398086d38 When checking the trace, it is notable that project panel updates its entire tree multiple times during flycheck: <img width="2032" height="1136" alt="image" src="https://github.com/user-attachments/assets/d1935e77-3b00-4be5-a12a-8a17a9d64202" /> [scrolling.trace.zip](https://github.com/user-attachments/files/22710852/scrolling.trace.zip) Turns out, `target/debug` directory is loaded by Zed (presumably, reported by langserver as there are sources generated by bindgen and proto that need to be loaded), and `target/debug/build` directory received multiple events of a `None` kind for Zed, which trigger the rescans. Rework the logic to omit the `None`-kind events in Zed, and to avoid excessive repo updates if not needed. Release Notes: - Improved worktree FS event emits in gitignored directories --------- Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
co-authored by
Cole Miller
parent
46b6adadf9
commit
469ecfbe13
+13
-7
@@ -753,7 +753,9 @@ impl Fs for RealFs {
|
||||
Some(PathEventKind::Removed)
|
||||
} else if event.flags.contains(StreamFlags::ITEM_CREATED) {
|
||||
Some(PathEventKind::Created)
|
||||
} else if event.flags.contains(StreamFlags::ITEM_MODIFIED) {
|
||||
} else if event.flags.contains(StreamFlags::ITEM_MODIFIED)
|
||||
| event.flags.contains(StreamFlags::ITEM_RENAMED)
|
||||
{
|
||||
Some(PathEventKind::Changed)
|
||||
} else {
|
||||
None
|
||||
@@ -1261,7 +1263,7 @@ impl FakeFs {
|
||||
async move {
|
||||
while let Ok(git_event) = rx.recv().await {
|
||||
if let Some(mut state) = this.state.try_lock() {
|
||||
state.emit_event([(git_event, None)]);
|
||||
state.emit_event([(git_event, Some(PathEventKind::Changed))]);
|
||||
} else {
|
||||
panic!("Failed to lock file system state, this execution would have caused a test hang");
|
||||
}
|
||||
@@ -1308,7 +1310,7 @@ impl FakeFs {
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
state.emit_event([(path.to_path_buf(), None)]);
|
||||
state.emit_event([(path.to_path_buf(), Some(PathEventKind::Changed))]);
|
||||
}
|
||||
|
||||
pub async fn insert_file(&self, path: impl AsRef<Path>, content: Vec<u8>) {
|
||||
@@ -1331,7 +1333,7 @@ impl FakeFs {
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
state.emit_event([(path, None)]);
|
||||
state.emit_event([(path, Some(PathEventKind::Created))]);
|
||||
}
|
||||
|
||||
fn write_file_internal(
|
||||
@@ -1522,7 +1524,7 @@ impl FakeFs {
|
||||
|
||||
drop(repo_state);
|
||||
if emit_git_event {
|
||||
state.emit_event([(dot_git, None)]);
|
||||
state.emit_event([(dot_git, Some(PathEventKind::Changed))]);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
@@ -1573,7 +1575,7 @@ impl FakeFs {
|
||||
|
||||
if emit_git_event {
|
||||
drop(repo_state);
|
||||
state.emit_event([(canonical_path, None)]);
|
||||
state.emit_event([(canonical_path, Some(PathEventKind::Changed))]);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
@@ -1886,6 +1888,10 @@ impl FakeFs {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn emit_fs_event(&self, path: impl Into<PathBuf>, event: Option<PathEventKind>) {
|
||||
self.state.lock().emit_event(std::iter::once((path, event)));
|
||||
}
|
||||
|
||||
fn simulate_random_delay(&self) -> impl futures::Future<Output = ()> {
|
||||
self.executor.simulate_random_delay()
|
||||
}
|
||||
@@ -2053,7 +2059,7 @@ impl Fs for FakeFs {
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
state.emit_event([(path, None)]);
|
||||
state.emit_event([(path, Some(PathEventKind::Created))]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user