project panel: Make updates asynchronous (#38881)

Closes #ISSUE

Release Notes:

- project panel: Revamped how project panel entries are refreshed, which
should lead to a significantly smoother experience when working in large
projects.

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
Piotr Osiewicz 2025-10-02 08:10:09 +02:00 committed by GitHub
parent b5d57598b6
commit a49b2d5bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 97395 additions and 609 deletions

2
Cargo.lock generated
View file

@ -12161,6 +12161,7 @@ dependencies = [
"client",
"collections",
"command_palette_hooks",
"criterion",
"db",
"editor",
"file_icons",
@ -12171,6 +12172,7 @@ dependencies = [
"menu",
"pretty_assertions",
"project",
"rayon",
"schemars 1.0.1",
"search",
"serde",

View file

@ -5537,17 +5537,6 @@ impl Completion {
}
}
pub fn sort_worktree_entries(entries: &mut [impl AsRef<Entry>]) {
entries.sort_by(|entry_a, entry_b| {
let entry_a = entry_a.as_ref();
let entry_b = entry_b.as_ref();
compare_paths(
(entry_a.path.as_std_path(), entry_a.is_file()),
(entry_b.path.as_std_path(), entry_b.is_file()),
)
});
}
fn proto_to_prompt(level: proto::language_server_prompt_request::Level) -> gpui::PromptLevel {
match level {
proto::language_server_prompt_request::Level::Info(_) => gpui::PromptLevel::Info,

View file

@ -8,6 +8,10 @@ license = "GPL-3.0-or-later"
[lints]
workspace = true
[[bench]]
name = "sorting"
harness = false
[lib]
path = "src/project_panel.rs"
doctest = false
@ -32,6 +36,7 @@ serde_json.workspace = true
settings.workspace = true
smallvec.workspace = true
theme.workspace = true
rayon.workspace = true
ui.workspace = true
util.workspace = true
client.workspace = true
@ -44,6 +49,7 @@ workspace-hack.workspace = true
[dev-dependencies]
client = { workspace = true, features = ["test-support"] }
criterion.workspace = true
editor = { workspace = true, features = ["test-support"] }
gpui = { workspace = true, features = ["test-support"] }
language = { workspace = true, features = ["test-support"] }

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,54 @@
use criterion::{Criterion, criterion_group, criterion_main};
use project::{Entry, EntryKind, GitEntry, ProjectEntryId};
use project_panel::par_sort_worktree_entries;
use std::sync::Arc;
use util::rel_path::RelPath;
fn load_linux_repo_snapshot() -> Vec<GitEntry> {
let file = std::fs::read_to_string(
"/Users/hiro/Projects/zed/crates/project_panel/benches/linux_repo_snapshot.txt",
)
.expect("Failed to read file");
file.lines()
.filter_map(|line| {
let kind = match line.chars().next() {
Some('f') => EntryKind::File,
Some('d') => EntryKind::Dir,
_ => return None,
};
let entry = Entry {
kind,
path: Arc::from(RelPath::unix(&(line.trim_end()[2..])).unwrap()),
id: ProjectEntryId::default(),
size: 0,
inode: 0,
mtime: None,
canonical_path: None,
is_ignored: false,
is_always_included: false,
is_external: false,
is_private: false,
char_bag: Default::default(),
is_fifo: false,
};
Some(GitEntry {
entry,
git_summary: Default::default(),
})
})
.collect()
}
fn criterion_benchmark(c: &mut Criterion) {
let snapshot = load_linux_repo_snapshot();
c.bench_function("Sort linux worktree snapshot", |b| {
b.iter_batched(
|| snapshot.clone(),
|mut snapshot| par_sort_worktree_entries(&mut snapshot),
criterion::BatchSize::LargeInput,
);
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,8 @@ use std::{
sync::LazyLock,
};
use crate::rel_path::RelPath;
static HOME_DIR: OnceLock<PathBuf> = OnceLock::new();
/// Returns the path to the user's home directory.
@ -795,6 +797,81 @@ fn natural_sort(a: &str, b: &str) -> Ordering {
}
}
}
pub fn compare_rel_paths(
(path_a, a_is_file): (&RelPath, bool),
(path_b, b_is_file): (&RelPath, bool),
) -> Ordering {
let mut components_a = path_a.components();
let mut components_b = path_b.components();
fn stem_and_extension(filename: &str) -> (Option<&str>, Option<&str>) {
if filename.is_empty() {
return (None, None);
}
match filename.rsplit_once('.') {
// Case 1: No dot was found. The entire name is the stem.
None => (Some(filename), None),
// Case 2: A dot was found.
Some((before, after)) => {
// This is the crucial check for dotfiles like ".bashrc".
// If `before` is empty, the dot was the first character.
// In that case, we revert to the "whole name is the stem" logic.
if before.is_empty() {
(Some(filename), None)
} else {
// Otherwise, we have a standard stem and extension.
(Some(before), Some(after))
}
}
}
}
loop {
match (components_a.next(), components_b.next()) {
(Some(component_a), Some(component_b)) => {
let a_is_file = a_is_file && components_a.rest().is_empty();
let b_is_file = b_is_file && components_b.rest().is_empty();
let ordering = a_is_file.cmp(&b_is_file).then_with(|| {
let (a_stem, a_extension) = a_is_file
.then(|| stem_and_extension(component_a))
.unwrap_or_default();
let path_string_a = if a_is_file { a_stem } else { Some(component_a) };
let (b_stem, b_extension) = b_is_file
.then(|| stem_and_extension(component_b))
.unwrap_or_default();
let path_string_b = if b_is_file { b_stem } else { Some(component_b) };
let compare_components = match (path_string_a, path_string_b) {
(Some(a), Some(b)) => natural_sort(&a, &b),
(Some(_), None) => Ordering::Greater,
(None, Some(_)) => Ordering::Less,
(None, None) => Ordering::Equal,
};
compare_components.then_with(|| {
if a_is_file && b_is_file {
let ext_a = a_extension.unwrap_or_default();
let ext_b = b_extension.unwrap_or_default();
ext_a.cmp(ext_b)
} else {
Ordering::Equal
}
})
});
if !ordering.is_eq() {
return ordering;
}
}
(Some(_), None) => break Ordering::Greater,
(None, Some(_)) => break Ordering::Less,
(None, None) => break Ordering::Equal,
}
}
}
pub fn compare_paths(
(path_a, a_is_file): (&Path, bool),

View file

@ -2743,6 +2743,7 @@ mod tests {
})
.await
.unwrap();
cx.run_until_parked();
assert_eq!(cx.update(|cx| cx.windows().len()), 1);
let window = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
let workspace = window.root(cx).unwrap();
@ -2794,6 +2795,7 @@ mod tests {
})
.unwrap()
.await;
cx.run_until_parked();
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(
@ -2832,6 +2834,7 @@ mod tests {
})
.unwrap()
.await;
cx.run_until_parked();
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(
@ -2881,6 +2884,7 @@ mod tests {
})
.unwrap()
.await;
cx.run_until_parked();
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(
@ -2930,6 +2934,7 @@ mod tests {
})
.unwrap()
.await;
cx.run_until_parked();
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(workspace, Path::new(path!("/d.txt")), rel_path(""), cx);

View file

@ -51,7 +51,9 @@ extend-exclude = [
# typos-cli doesn't understand our `vˇariable` markup
"crates/editor/src/hover_links.rs",
# typos-cli doesn't understand `setis` is intentional test case
"crates/editor/src/code_completion_tests.rs"
"crates/editor/src/code_completion_tests.rs",
# Linux repository structure is not a valid text, hence we should not check it for typos
"crates/project_panel/benches/linux_repo_snapshot.txt",
]
[default]