From 38e5facb11e7243515813b93c38c5e2a8f22e05e Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 6 Oct 2025 16:13:54 +0200 Subject: [PATCH] Manually annotate each fiber --- Cargo.lock | 1 - crates/git/Cargo.toml | 1 - crates/git/src/repository.rs | 17 +- crates/gpui/src/executor.rs | 5 +- crates/project_panel/src/project_panel.rs | 411 +++++++++++----------- 5 files changed, 218 insertions(+), 217 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8dc02fe7129109fc13abd223dc48263b719b8d35..2f3b01c0522928aaec9e2e4afabfcd5c8d97bee8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6812,7 +6812,6 @@ dependencies = [ "thiserror 2.0.12", "time", "tracy-client", - "tracy-client-sys", "unindent", "url", "util", diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.toml index 2e000ef1d422e12ccdaeadd0787a0bc30b4cd42d..69e8f544fc54e10ee9f1b450c8008ae6e440418a 100644 --- a/crates/git/Cargo.toml +++ b/crates/git/Cargo.toml @@ -42,7 +42,6 @@ futures.workspace = true workspace-hack.workspace = true profiling.workspace = true tracy-client.workspace = true -tracy-client-sys.workspace = true [dev-dependencies] pretty_assertions.workspace = true diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 9a58c4dabba5f242d4810a2edd606f336b71c0cb..060faa2200c9da522fec3efdb66ed7bcfcc21e56 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -626,18 +626,6 @@ pub async fn get_git_committer(cx: &AsyncApp) -> GitCommitter { .await } -#[repr(C)] -#[derive(Copy, Clone)] -struct ___tracy_source_location_data { - pub name: *const ::std::os::raw::c_char, - pub function: *const ::std::os::raw::c_char, - pub file: *const ::std::os::raw::c_char, - pub line: u32, - pub color: u32, -} - -unsafe impl Send for ___tracy_source_location_data {} - impl GitRepository for RealGitRepository { fn reload_index(&self) { if let Ok(mut index) = self.repository.lock().index() { @@ -699,9 +687,8 @@ impl GitRepository for RealGitRepository { else { return future::ready(Err(anyhow!("no working directory"))).boxed(); }; - dbg!("Load commit"); let git_binary_path = self.any_git_binary_path.clone(); - cx.background_spawn(async move { + cx.background_spawn(tracy_client::fiber!("load_commit", async move { let _zone = tracy_client::span_unchecked!(); let show_output = util::command::new_smol_command(&git_binary_path) .current_dir(&working_directory) @@ -812,7 +799,7 @@ impl GitRepository for RealGitRepository { } Ok(CommitDiff { files }) - }) + })) .boxed() } diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index 5b8339a8fce5b40b4326f3e38ac4f993bf4ebaa8..0b28dd030baff6bc95ede07e50e358660a9c1353 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -168,9 +168,8 @@ impl BackgroundExecutor { label: Option, ) -> Task { let dispatcher = self.dispatcher.clone(); - let (runnable, task) = async_task::spawn(tracy_client::fiber!(future), move |runnable| { - dispatcher.dispatch(runnable, label) - }); + let (runnable, task) = + async_task::spawn(future, move |runnable| dispatcher.dispatch(runnable, label)); runnable.schedule(); Task(TaskState::Spawned(task)) } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 3328e66737f42ff062ed42e189e6b81f08bc77b5..748b5390231ad5dd51b7452c55871774dda6dd84 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -3207,227 +3207,244 @@ impl ProjectPanel { let hide_root = settings.hide_root && visible_worktrees.len() == 1; self.update_visible_entries_task = cx.spawn_in(window, async move |this, cx| { let new_state = cx - .background_spawn(async move { - let _zone = tracy_client::span_unchecked!(); - for worktree_snapshot in visible_worktrees { - let worktree_id = worktree_snapshot.id(); - - let expanded_dir_ids = match new_state.expanded_dir_ids.entry(worktree_id) { - hash_map::Entry::Occupied(e) => e.into_mut(), - hash_map::Entry::Vacant(e) => { - // The first time a worktree's root entry becomes available, - // mark that root entry as expanded. - if let Some(entry) = worktree_snapshot.root_entry() { - e.insert(vec![entry.id]).as_slice() + .background_spawn(tracy_client::fiber!( + "update_visible_entries_task", + async move { + let _zone = tracy_client::span_unchecked!(); + for worktree_snapshot in visible_worktrees { + let worktree_id = worktree_snapshot.id(); + + let expanded_dir_ids = + match new_state.expanded_dir_ids.entry(worktree_id) { + hash_map::Entry::Occupied(e) => e.into_mut(), + hash_map::Entry::Vacant(e) => { + // The first time a worktree's root entry becomes available, + // mark that root entry as expanded. + if let Some(entry) = worktree_snapshot.root_entry() { + e.insert(vec![entry.id]).as_slice() + } else { + &[] + } + } + }; + + let mut new_entry_parent_id = None; + let mut new_entry_kind = EntryKind::Dir; + if let Some(edit_state) = &new_state.edit_state + && edit_state.worktree_id == worktree_id + && edit_state.is_new_entry() + { + new_entry_parent_id = Some(edit_state.entry_id); + new_entry_kind = if edit_state.is_dir { + EntryKind::Dir } else { - &[] - } + EntryKind::File + }; } - }; - - let mut new_entry_parent_id = None; - let mut new_entry_kind = EntryKind::Dir; - if let Some(edit_state) = &new_state.edit_state - && edit_state.worktree_id == worktree_id - && edit_state.is_new_entry() - { - new_entry_parent_id = Some(edit_state.entry_id); - new_entry_kind = if edit_state.is_dir { - EntryKind::Dir - } else { - EntryKind::File - }; - } - let mut visible_worktree_entries = Vec::new(); - let mut entry_iter = - GitTraversal::new(&repo_snapshots, worktree_snapshot.entries(true, 0)); - let mut auto_folded_ancestors = vec![]; - let worktree_abs_path = worktree_snapshot.abs_path(); - while let Some(entry) = entry_iter.entry() { - if hide_root && Some(entry.entry) == worktree_snapshot.root_entry() { - if new_entry_parent_id == Some(entry.id) { + let mut visible_worktree_entries = Vec::new(); + let mut entry_iter = GitTraversal::new( + &repo_snapshots, + worktree_snapshot.entries(true, 0), + ); + let mut auto_folded_ancestors = vec![]; + let worktree_abs_path = worktree_snapshot.abs_path(); + while let Some(entry) = entry_iter.entry() { + if hide_root && Some(entry.entry) == worktree_snapshot.root_entry() + { + if new_entry_parent_id == Some(entry.id) { + visible_worktree_entries.push(Self::create_new_git_entry( + entry.entry, + entry.git_summary, + new_entry_kind, + )); + new_entry_parent_id = None; + } + entry_iter.advance(); + continue; + } + if auto_collapse_dirs && entry.kind.is_dir() { + auto_folded_ancestors.push(entry.id); + if !new_state.unfolded_dir_ids.contains(&entry.id) + && let Some(root_path) = worktree_snapshot.root_entry() + { + let mut child_entries = + worktree_snapshot.child_entries(&entry.path); + if let Some(child) = child_entries.next() + && entry.path != root_path.path + && child_entries.next().is_none() + && child.kind.is_dir() + { + entry_iter.advance(); + + continue; + } + } + let depth = old_ancestors + .get(&entry.id) + .map(|ancestor| ancestor.current_ancestor_depth) + .unwrap_or_default() + .min(auto_folded_ancestors.len()); + if let Some(edit_state) = &mut new_state.edit_state + && edit_state.entry_id == entry.id + { + edit_state.depth = depth; + } + let mut ancestors = std::mem::take(&mut auto_folded_ancestors); + if ancestors.len() > 1 { + ancestors.reverse(); + new_state.ancestors.insert( + entry.id, + FoldedAncestors { + current_ancestor_depth: depth, + ancestors, + }, + ); + } + } + auto_folded_ancestors.clear(); + if !hide_gitignore || !entry.is_ignored { + visible_worktree_entries.push(entry.to_owned()); + } + let precedes_new_entry = + if let Some(new_entry_id) = new_entry_parent_id { + entry.id == new_entry_id || { + new_state.ancestors.get(&entry.id).is_some_and( + |entries| entries.ancestors.contains(&new_entry_id), + ) + } + } else { + false + }; + if precedes_new_entry && (!hide_gitignore || !entry.is_ignored) { visible_worktree_entries.push(Self::create_new_git_entry( entry.entry, entry.git_summary, new_entry_kind, )); - new_entry_parent_id = None; } - entry_iter.advance(); - continue; - } - if auto_collapse_dirs && entry.kind.is_dir() { - auto_folded_ancestors.push(entry.id); - if !new_state.unfolded_dir_ids.contains(&entry.id) - && let Some(root_path) = worktree_snapshot.root_entry() - { - let mut child_entries = - worktree_snapshot.child_entries(&entry.path); - if let Some(child) = child_entries.next() - && entry.path != root_path.path - && child_entries.next().is_none() - && child.kind.is_dir() - { - entry_iter.advance(); - continue; - } - } - let depth = old_ancestors - .get(&entry.id) - .map(|ancestor| ancestor.current_ancestor_depth) - .unwrap_or_default() - .min(auto_folded_ancestors.len()); - if let Some(edit_state) = &mut new_state.edit_state - && edit_state.entry_id == entry.id + let (depth, chars) = if Some(entry.entry) + == worktree_snapshot.root_entry() { - edit_state.depth = depth; - } - let mut ancestors = std::mem::take(&mut auto_folded_ancestors); - if ancestors.len() > 1 { - ancestors.reverse(); - new_state.ancestors.insert( - entry.id, - FoldedAncestors { - current_ancestor_depth: depth, - ancestors, - }, - ); - } - } - auto_folded_ancestors.clear(); - if !hide_gitignore || !entry.is_ignored { - visible_worktree_entries.push(entry.to_owned()); - } - let precedes_new_entry = if let Some(new_entry_id) = new_entry_parent_id - { - entry.id == new_entry_id || { - new_state.ancestors.get(&entry.id).is_some_and(|entries| { - entries.ancestors.contains(&new_entry_id) - }) - } - } else { - false - }; - if precedes_new_entry && (!hide_gitignore || !entry.is_ignored) { - visible_worktree_entries.push(Self::create_new_git_entry( - entry.entry, - entry.git_summary, - new_entry_kind, - )); - } - - let (depth, chars) = if Some(entry.entry) - == worktree_snapshot.root_entry() - { - let Some(path_name) = worktree_abs_path.file_name() else { - continue; - }; - let depth = 0; - (depth, path_name.to_string_lossy().chars().count()) - } else if entry.is_file() { - let Some(path_name) = entry - .path - .file_name() - .with_context(|| { - format!("Non-root entry has no file name: {entry:?}") - }) - .log_err() - else { - continue; - }; - let depth = entry.path.ancestors().count() - 1; - (depth, path_name.chars().count()) - } else { - let path = new_state - .ancestors - .get(&entry.id) - .and_then(|ancestors| { - let outermost_ancestor = ancestors.ancestors.last()?; - let root_folded_entry = worktree_snapshot - .entry_for_id(*outermost_ancestor)? - .path - .as_ref(); - entry.path.strip_prefix(root_folded_entry).ok().and_then( - |suffix| { - Some( - RelPath::unix(root_folded_entry.file_name()?) + let Some(path_name) = worktree_abs_path.file_name() else { + continue; + }; + let depth = 0; + (depth, path_name.to_string_lossy().chars().count()) + } else if entry.is_file() { + let Some(path_name) = entry + .path + .file_name() + .with_context(|| { + format!("Non-root entry has no file name: {entry:?}") + }) + .log_err() + else { + continue; + }; + let depth = entry.path.ancestors().count() - 1; + (depth, path_name.chars().count()) + } else { + let path = new_state + .ancestors + .get(&entry.id) + .and_then(|ancestors| { + let outermost_ancestor = ancestors.ancestors.last()?; + let root_folded_entry = worktree_snapshot + .entry_for_id(*outermost_ancestor)? + .path + .as_ref(); + entry + .path + .strip_prefix(root_folded_entry) + .ok() + .and_then(|suffix| { + Some( + RelPath::unix( + root_folded_entry.file_name()?, + ) .unwrap() .join(suffix), - ) - }, - ) - }) - .or_else(|| { - entry.path.file_name().map(|file_name| { - RelPath::unix(file_name).unwrap().into() + ) + }) }) - }) - .unwrap_or_else(|| entry.path.clone()); - let depth = path.components().count(); - (depth, path.as_unix_str().chars().count()) - }; - let width_estimate = - item_width_estimate(depth, chars, entry.canonical_path.is_some()); - - match max_width_item.as_mut() { - Some((id, worktree_id, width)) => { - if *width < width_estimate { - *id = entry.id; - *worktree_id = worktree_snapshot.id(); - *width = width_estimate; + .or_else(|| { + entry.path.file_name().map(|file_name| { + RelPath::unix(file_name).unwrap().into() + }) + }) + .unwrap_or_else(|| entry.path.clone()); + let depth = path.components().count(); + (depth, path.as_unix_str().chars().count()) + }; + let width_estimate = item_width_estimate( + depth, + chars, + entry.canonical_path.is_some(), + ); + + match max_width_item.as_mut() { + Some((id, worktree_id, width)) => { + if *width < width_estimate { + *id = entry.id; + *worktree_id = worktree_snapshot.id(); + *width = width_estimate; + } + } + None => { + max_width_item = + Some((entry.id, worktree_snapshot.id(), width_estimate)) } } - None => { - max_width_item = - Some((entry.id, worktree_snapshot.id(), width_estimate)) + + if expanded_dir_ids.binary_search(&entry.id).is_err() + && entry_iter.advance_to_sibling() + { + continue; } + entry_iter.advance(); } - if expanded_dir_ids.binary_search(&entry.id).is_err() - && entry_iter.advance_to_sibling() - { - continue; + par_sort_worktree_entries(&mut visible_worktree_entries); + new_state.visible_entries.push(VisibleEntriesForWorktree { + worktree_id, + entries: visible_worktree_entries, + index: OnceCell::new(), + }) + } + if let Some((project_entry_id, worktree_id, _)) = max_width_item { + let mut visited_worktrees_length = 0; + let index = + new_state + .visible_entries + .iter() + .find_map(|visible_entries| { + if worktree_id == visible_entries.worktree_id { + visible_entries + .entries + .iter() + .position(|entry| entry.id == project_entry_id) + } else { + visited_worktrees_length += + visible_entries.entries.len(); + None + } + }); + if let Some(index) = index { + new_state.max_width_item_index = + Some(visited_worktrees_length + index); } - entry_iter.advance(); } - - par_sort_worktree_entries(&mut visible_worktree_entries); - new_state.visible_entries.push(VisibleEntriesForWorktree { - worktree_id, - entries: visible_worktree_entries, - index: OnceCell::new(), - }) - } - if let Some((project_entry_id, worktree_id, _)) = max_width_item { - let mut visited_worktrees_length = 0; - let index = new_state - .visible_entries - .iter() - .find_map(|visible_entries| { - if worktree_id == visible_entries.worktree_id { - visible_entries - .entries - .iter() - .position(|entry| entry.id == project_entry_id) - } else { - visited_worktrees_length += visible_entries.entries.len(); - None - } + if let Some((worktree_id, entry_id)) = new_selected_entry { + new_state.selection = Some(SelectedEntry { + worktree_id, + entry_id, }); - if let Some(index) = index { - new_state.max_width_item_index = Some(visited_worktrees_length + index); } + new_state } - if let Some((worktree_id, entry_id)) = new_selected_entry { - new_state.selection = Some(SelectedEntry { - worktree_id, - entry_id, - }); - } - new_state - }) + )) .await; this.update_in(cx, |this, window, cx| { this.state = new_state;