More experiments

Jakub Konka created

Change summary

Cargo.lock                   |   7 
Cargo.toml                   |   4 
crates/git/src/repository.rs | 248 +++++++++++++++++++------------------
crates/gpui/src/executor.rs  |  12 -
crates/zed/Cargo.toml        |   2 
5 files changed, 135 insertions(+), 138 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -12079,7 +12079,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
 dependencies = [
  "profiling-procmacros",
- "tracy-client",
 ]
 
 [[package]]
@@ -16899,8 +16898,6 @@ dependencies = [
 [[package]]
 name = "tracy-client"
 version = "0.18.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ef54005d3d760186fd662dad4b7bb27ecd5531cdef54d1573ebd3f20a9205ed7"
 dependencies = [
  "loom",
  "once_cell",
@@ -16910,11 +16907,9 @@ dependencies = [
 [[package]]
 name = "tracy-client-sys"
 version = "0.26.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "319c70195101a93f56db4c74733e272d720768e13471f400c78406a326b172b0"
 dependencies = [
  "cc",
- "windows-targets 0.52.6",
+ "windows-targets 0.48.5",
 ]
 
 [[package]]

Cargo.toml 🔗

@@ -667,8 +667,8 @@ tokio = { version = "1" }
 tokio-tungstenite = { version = "0.26", features = ["__rustls-tls"] }
 toml = "0.8"
 tower-http = "0.4.4"
-tracy-client = { version = "0.18.2", features = ["fibers"] }
-tracy-client-sys = { version = "0.26.1", features = ["fibers"] }
+tracy-client = { path = "../rust_tracy_client/tracy-client", features = ["fibers"] }
+tracy-client-sys = { path = "../rust_tracy_client/tracy-client-sys", features = ["fibers"] }
 tree-sitter = { version = "0.25.10", features = ["wasm"] }
 tree-sitter-bash = "0.25.0"
 tree-sitter-c = "0.23"

crates/git/src/repository.rs 🔗

@@ -701,135 +701,147 @@ impl GitRepository for RealGitRepository {
         };
         dbg!("Load commit");
         let git_binary_path = self.any_git_binary_path.clone();
-        cx.background_spawn(async move {
-            let name = std::ffi::CString::new("fiber_load_bytes").unwrap();
-            let loc = ___tracy_source_location_data {
-                name: name.as_ptr(),
-                function: name.as_ptr(),
-                file: name.as_ptr(),
-                line: 0,
-                color: 0,
-            };
-            let zone = unsafe {
-                // tracy_client_sys::___tracy_fiber_enter(name.as_ptr());
-                tracy_client_sys::___tracy_emit_zone_begin(std::mem::transmute(&loc as *const _), 1)
-            };
-
-            let show_output = util::command::new_smol_command(&git_binary_path)
-                .current_dir(&working_directory)
-                .args([
-                    "--no-optional-locks",
-                    "show",
-                    "--format=%P",
-                    "-z",
-                    "--no-renames",
-                    "--name-status",
-                ])
-                .arg(&commit)
-                .stdin(Stdio::null())
-                .stdout(Stdio::piped())
-                .stderr(Stdio::piped())
-                .output()
-                .await
-                .context("starting git show process")?;
-
-            let show_stdout = String::from_utf8_lossy(&show_output.stdout);
-            let mut lines = show_stdout.split('\n');
-            let parent_sha = lines.next().unwrap().trim().trim_end_matches('\0');
-            let changes = parse_git_diff_name_status(lines.next().unwrap_or(""));
+        let _zone = tracy_client::span!("load_commit");
+        cx.background_spawn(
+            tracy_client::Client::running()
+                .expect("tracy client not running")
+                .with_fiber("load_commit", async move {
+                    // let name = std::ffi::CString::new("fiber_load_bytes").unwrap();
+                    // let loc = ___tracy_source_location_data {
+                    //     name: name.as_ptr(),
+                    //     function: name.as_ptr(),
+                    //     file: name.as_ptr(),
+                    //     line: 0,
+                    //     color: 0,
+                    // };
+                    // let zone = unsafe {
+                    //     // tracy_client_sys::___tracy_fiber_enter(name.as_ptr());
+                    //     tracy_client_sys::___tracy_emit_zone_begin(
+                    //         std::mem::transmute(&loc as *const _),
+                    //         1,
+                    //     )
+                    // };
+
+                    let show_output = util::command::new_smol_command(&git_binary_path)
+                        .current_dir(&working_directory)
+                        .args([
+                            "--no-optional-locks",
+                            "show",
+                            "--format=%P",
+                            "-z",
+                            "--no-renames",
+                            "--name-status",
+                        ])
+                        .arg(&commit)
+                        .stdin(Stdio::null())
+                        .stdout(Stdio::piped())
+                        .stderr(Stdio::piped())
+                        .output()
+                        .await
+                        .context("starting git show process")?;
 
-            let mut cat_file_process = util::command::new_smol_command(&git_binary_path)
-                .current_dir(&working_directory)
-                .args(["--no-optional-locks", "cat-file", "--batch=%(objectsize)"])
-                .stdin(Stdio::piped())
-                .stdout(Stdio::piped())
-                .stderr(Stdio::piped())
-                .spawn()
-                .context("starting git cat-file process")?;
-
-            let mut files = Vec::<CommitFile>::new();
-            let mut stdin = BufWriter::with_capacity(512, cat_file_process.stdin.take().unwrap());
-            let mut stdout = BufReader::new(cat_file_process.stdout.take().unwrap());
-            let mut info_line = String::new();
-            let mut newline = [b'\0'];
-            for (path, status_code) in changes {
-                // git-show outputs `/`-delimited paths even on Windows.
-                let Some(rel_path) = RelPath::unix(path).log_err() else {
-                    continue;
-                };
+                    let show_stdout = String::from_utf8_lossy(&show_output.stdout);
+                    let mut lines = show_stdout.split('\n');
+                    let parent_sha = lines.next().unwrap().trim().trim_end_matches('\0');
+                    let changes = parse_git_diff_name_status(lines.next().unwrap_or(""));
 
-                match status_code {
-                    StatusCode::Modified => {
-                        stdin.write_all(commit.as_bytes()).await?;
-                        stdin.write_all(b":").await?;
-                        stdin.write_all(path.as_bytes()).await?;
-                        stdin.write_all(b"\n").await?;
-                        stdin.write_all(parent_sha.as_bytes()).await?;
-                        stdin.write_all(b":").await?;
-                        stdin.write_all(path.as_bytes()).await?;
-                        stdin.write_all(b"\n").await?;
-                    }
-                    StatusCode::Added => {
-                        stdin.write_all(commit.as_bytes()).await?;
-                        stdin.write_all(b":").await?;
-                        stdin.write_all(path.as_bytes()).await?;
-                        stdin.write_all(b"\n").await?;
-                    }
-                    StatusCode::Deleted => {
-                        stdin.write_all(parent_sha.as_bytes()).await?;
-                        stdin.write_all(b":").await?;
-                        stdin.write_all(path.as_bytes()).await?;
-                        stdin.write_all(b"\n").await?;
-                    }
-                    _ => continue,
-                }
-                stdin.flush().await?;
+                    let mut cat_file_process = util::command::new_smol_command(&git_binary_path)
+                        .current_dir(&working_directory)
+                        .args(["--no-optional-locks", "cat-file", "--batch=%(objectsize)"])
+                        .stdin(Stdio::piped())
+                        .stdout(Stdio::piped())
+                        .stderr(Stdio::piped())
+                        .spawn()
+                        .context("starting git cat-file process")?;
+
+                    let mut files = Vec::<CommitFile>::new();
+                    let mut stdin =
+                        BufWriter::with_capacity(512, cat_file_process.stdin.take().unwrap());
+                    let mut stdout = BufReader::new(cat_file_process.stdout.take().unwrap());
+                    let mut info_line = String::new();
+                    let mut newline = [b'\0'];
+                    for (path, status_code) in changes {
+                        // git-show outputs `/`-delimited paths even on Windows.
+                        let Some(rel_path) = RelPath::unix(path).log_err() else {
+                            continue;
+                        };
+
+                        match status_code {
+                            StatusCode::Modified => {
+                                stdin.write_all(commit.as_bytes()).await?;
+                                stdin.write_all(b":").await?;
+                                stdin.write_all(path.as_bytes()).await?;
+                                stdin.write_all(b"\n").await?;
+                                stdin.write_all(parent_sha.as_bytes()).await?;
+                                stdin.write_all(b":").await?;
+                                stdin.write_all(path.as_bytes()).await?;
+                                stdin.write_all(b"\n").await?;
+                            }
+                            StatusCode::Added => {
+                                stdin.write_all(commit.as_bytes()).await?;
+                                stdin.write_all(b":").await?;
+                                stdin.write_all(path.as_bytes()).await?;
+                                stdin.write_all(b"\n").await?;
+                            }
+                            StatusCode::Deleted => {
+                                stdin.write_all(parent_sha.as_bytes()).await?;
+                                stdin.write_all(b":").await?;
+                                stdin.write_all(path.as_bytes()).await?;
+                                stdin.write_all(b"\n").await?;
+                            }
+                            _ => continue,
+                        }
+                        stdin.flush().await?;
 
-                info_line.clear();
-                stdout.read_line(&mut info_line).await?;
-
-                let len = info_line.trim_end().parse().with_context(|| {
-                    format!("invalid object size output from cat-file {info_line}")
-                })?;
-                let mut text = vec![0; len];
-                stdout.read_exact(&mut text).await?;
-                stdout.read_exact(&mut newline).await?;
-                let text = String::from_utf8_lossy(&text).to_string();
-
-                let mut old_text = None;
-                let mut new_text = None;
-                match status_code {
-                    StatusCode::Modified => {
                         info_line.clear();
                         stdout.read_line(&mut info_line).await?;
+
                         let len = info_line.trim_end().parse().with_context(|| {
-                            format!("invalid object size output from cat-file {}", info_line)
+                            format!("invalid object size output from cat-file {info_line}")
                         })?;
-                        let mut parent_text = vec![0; len];
-                        stdout.read_exact(&mut parent_text).await?;
+                        let mut text = vec![0; len];
+                        stdout.read_exact(&mut text).await?;
                         stdout.read_exact(&mut newline).await?;
-                        old_text = Some(String::from_utf8_lossy(&parent_text).to_string());
-                        new_text = Some(text);
-                    }
-                    StatusCode::Added => new_text = Some(text),
-                    StatusCode::Deleted => old_text = Some(text),
-                    _ => continue,
-                }
+                        let text = String::from_utf8_lossy(&text).to_string();
+
+                        let mut old_text = None;
+                        let mut new_text = None;
+                        match status_code {
+                            StatusCode::Modified => {
+                                info_line.clear();
+                                stdout.read_line(&mut info_line).await?;
+                                let len = info_line.trim_end().parse().with_context(|| {
+                                    format!(
+                                        "invalid object size output from cat-file {}",
+                                        info_line
+                                    )
+                                })?;
+                                let mut parent_text = vec![0; len];
+                                stdout.read_exact(&mut parent_text).await?;
+                                stdout.read_exact(&mut newline).await?;
+                                old_text = Some(String::from_utf8_lossy(&parent_text).to_string());
+                                new_text = Some(text);
+                            }
+                            StatusCode::Added => new_text = Some(text),
+                            StatusCode::Deleted => old_text = Some(text),
+                            _ => continue,
+                        }
 
-                files.push(CommitFile {
-                    path: rel_path.into(),
-                    old_text,
-                    new_text,
-                })
-            }
+                        files.push(CommitFile {
+                            path: rel_path.into(),
+                            old_text,
+                            new_text,
+                        })
+                    }
 
-            unsafe {
-                tracy_client_sys::___tracy_emit_zone_end(zone);
-                // tracy_client_sys::___tracy_fiber_leave();
-            }
+                    // unsafe {
+                    //     tracy_client_sys::___tracy_emit_zone_end(zone);
+                    //     // tracy_client_sys::___tracy_fiber_leave();
+                    // }
 
-            Ok(CommitDiff { files })
-        })
+                    Ok(CommitDiff { files })
+                }),
+        )
         .boxed()
     }
 

crates/gpui/src/executor.rs 🔗

@@ -103,17 +103,7 @@ impl<T> Future for Task<T> {
     fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
         match unsafe { self.get_unchecked_mut() } {
             Task(TaskState::Ready(val)) => Poll::Ready(val.take().unwrap()),
-            Task(TaskState::Spawned(task)) => {
-                let name = std::ffi::CString::new("Fiber").unwrap();
-                unsafe {
-                    tracy_client_sys::___tracy_fiber_enter(name.as_ptr());
-                }
-                let res = task.poll(cx);
-                unsafe {
-                    tracy_client_sys::___tracy_fiber_leave();
-                }
-                res
-            }
+            Task(TaskState::Spawned(task)) => task.poll(cx),
         }
     }
 }

crates/zed/Cargo.toml 🔗

@@ -19,7 +19,7 @@ name = "zed"
 path = "src/main.rs"
 
 [features]
-profile-with-tracy = ["dep:tracy-client", "profiling/profile-with-tracy"]
+profile-with-tracy = ["dep:tracy-client"]#, "profiling/profile-with-tracy"]
 profile-with-tracy-memory = ["profile-with-tracy"]
 
 [dependencies]