From 701fa4daa8c3e0b397b099b28a4530da37badd94 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 16 Jun 2025 17:06:16 -0400 Subject: [PATCH] Reduce allocations on project type detection (#32818) Release Notes: - N/A --- crates/client/src/telemetry.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 93f6762725..43f189eaf9 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -374,22 +374,28 @@ impl Telemetry { return None; } - let mut project_types: HashSet = HashSet::new(); + let mut project_types: HashSet<&str> = HashSet::new(); for (path, _, _) in updated_entries_set.iter() { let Some(file_name) = path.file_name().and_then(|f| f.to_str()) else { continue; }; - if file_name == "pnpm-lock.yaml" { - project_types.insert("pnpm".to_string()); + let project_type = if file_name == "pnpm-lock.yaml" { + Some("pnpm") } else if file_name == "yarn.lock" { - project_types.insert("yarn".to_string()); + Some("yarn") } else if file_name == "package.json" { - project_types.insert("node".to_string()); + Some("node") } else if DOTNET_PROJECT_FILES_REGEX.is_match(file_name) { - project_types.insert("dotnet".to_string()); - } + Some("dotnet") + } else { + None + }; + + if let Some(project_type) = project_type { + project_types.insert(project_type); + }; } if !project_types.is_empty() { @@ -398,7 +404,8 @@ impl Telemetry { .insert(worktree_id); } - let mut project_names_vec: Vec = project_types.into_iter().collect(); + let mut project_names_vec: Vec = + project_types.into_iter().map(String::from).collect(); project_names_vec.sort(); Some(project_names_vec) }