perf: Add on search + fixups (#40537)

Nia created

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Change summary

Cargo.lock                          |  1 +
crates/search/Cargo.toml            |  1 +
crates/search/src/buffer_search.rs  | 12 ++++++++++++
crates/search/src/project_search.rs | 11 +++++++++++
tooling/perf/src/implementation.rs  |  9 ++++++---
tooling/perf/src/main.rs            |  2 +-
6 files changed, 32 insertions(+), 4 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -14867,6 +14867,7 @@ dependencies = [
  "ui",
  "unindent",
  "util",
+ "util_macros",
  "workspace",
  "zed_actions",
 ]

crates/search/Cargo.toml 🔗

@@ -39,6 +39,7 @@ smol.workspace = true
 theme.workspace = true
 ui.workspace = true
 util.workspace = true
+util_macros.workspace = true
 workspace.workspace = true
 zed_actions.workspace = true
 

crates/search/src/buffer_search.rs 🔗

@@ -1524,6 +1524,7 @@ mod tests {
     use settings::{SearchSettingsContent, SettingsStore};
     use smol::stream::StreamExt as _;
     use unindent::Unindent as _;
+    use util_macros::perf;
 
     fn init_globals(cx: &mut TestAppContext) {
         cx.update(|cx| {
@@ -1580,6 +1581,7 @@ mod tests {
         (editor.unwrap(), search_bar, cx)
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_simple(cx: &mut TestAppContext) {
         let (editor, search_bar, cx) = init_test(cx);
@@ -1860,6 +1862,7 @@ mod tests {
             .collect::<Vec<_>>()
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_option_handling(cx: &mut TestAppContext) {
         let (editor, search_bar, cx) = init_test(cx);
@@ -1920,6 +1923,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_select_all_matches(cx: &mut TestAppContext) {
         init_globals(cx);
@@ -2128,6 +2132,7 @@ mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_query_with_match_whole_word(cx: &mut TestAppContext) {
         init_globals(cx);
@@ -2213,6 +2218,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_query_history(cx: &mut TestAppContext) {
         let (_editor, search_bar, cx) = init_test(cx);
@@ -2362,6 +2368,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_replace_simple(cx: &mut TestAppContext) {
         let (editor, search_bar, cx) = init_test(cx);
@@ -2529,6 +2536,7 @@ mod tests {
         );
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_replace_special_characters(cx: &mut TestAppContext) {
         let (editor, search_bar, cx) = init_test(cx);
@@ -2592,6 +2600,7 @@ mod tests {
         .await;
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_find_matches_in_selections_singleton_buffer_multiple_selections(
         cx: &mut TestAppContext,
@@ -2658,6 +2667,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_find_matches_in_selections_multiple_excerpts_buffer_multiple_selections(
         cx: &mut TestAppContext,
@@ -2744,6 +2754,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_invalid_regexp_search_after_valid(cx: &mut TestAppContext) {
         let (editor, search_bar, cx) = init_test(cx);
@@ -2779,6 +2790,7 @@ mod tests {
         });
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_options_changes(cx: &mut TestAppContext) {
         let (_editor, search_bar, cx) = init_test(cx);

crates/search/src/project_search.rs 🔗

@@ -2359,8 +2359,10 @@ pub mod tests {
     use serde_json::json;
     use settings::SettingsStore;
     use util::{path, paths::PathStyle, rel_path::rel_path};
+    use util_macros::perf;
     use workspace::DeploySearch;
 
+    #[perf]
     #[gpui::test]
     async fn test_project_search(cx: &mut TestAppContext) {
         init_test(cx);
@@ -2498,6 +2500,7 @@ pub mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_deploy_project_search_focus(cx: &mut TestAppContext) {
         init_test(cx);
@@ -2738,6 +2741,7 @@ pub mod tests {
         }).unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_filters_consider_toggle_state(cx: &mut TestAppContext) {
         init_test(cx);
@@ -2858,6 +2862,7 @@ pub mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_new_project_search_focus(cx: &mut TestAppContext) {
         init_test(cx);
@@ -3153,6 +3158,7 @@ pub mod tests {
                 });}).unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_new_project_search_in_directory(cx: &mut TestAppContext) {
         init_test(cx);
@@ -3279,6 +3285,7 @@ pub mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_query_history(cx: &mut TestAppContext) {
         init_test(cx);
@@ -3609,6 +3616,7 @@ pub mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_search_query_history_with_multiple_views(cx: &mut TestAppContext) {
         init_test(cx);
@@ -3832,6 +3840,7 @@ pub mod tests {
         assert_eq!(active_query(&search_view_1, cx), "");
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_deploy_search_with_multiple_panes(cx: &mut TestAppContext) {
         init_test(cx);
@@ -3991,6 +4000,7 @@ pub mod tests {
             .unwrap();
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_scroll_search_results_to_top(cx: &mut TestAppContext) {
         init_test(cx);
@@ -4071,6 +4081,7 @@ pub mod tests {
             .expect("unable to update search view");
     }
 
+    #[perf]
     #[gpui::test]
     async fn test_buffer_search_query_reused(cx: &mut TestAppContext) {
         init_test(cx);

tooling/perf/src/implementation.rs 🔗

@@ -420,13 +420,16 @@ impl std::fmt::Display for PerfReport {
         for (cat, delta) in sorted.into_iter().rev() {
             const SIGN_POS: &str = "↑";
             const SIGN_NEG: &str = "↓";
-            const SIGN_NEUTRAL: &str = "±";
+            const SIGN_NEUTRAL_POS: &str = "±↑";
+            const SIGN_NEUTRAL_NEG: &str = "±↓";
 
             let prettify = |time: f64| {
                 let sign = if time > 0.05 {
                     SIGN_POS
-                } else if time < 0.05 && time > -0.05 {
-                    SIGN_NEUTRAL
+                } else if time > 0. {
+                    SIGN_NEUTRAL_POS
+                } else if time > -0.05 {
+                    SIGN_NEUTRAL_NEG
                 } else {
                     SIGN_NEG
                 };

tooling/perf/src/main.rs 🔗

@@ -228,8 +228,8 @@ fn compare_profiles(args: &[String]) {
                 a.strip_prefix("--save=")
                     .expect("FATAL: save param formatted incorrectly"),
             );
+            ident_idx = 1;
         }
-        ident_idx = 1;
     });
     let ident_new = args
         .get(ident_idx)