History

perf: Fixup ordering, fix pathing, docs (#38970)

Release Notes: - N/A

Nia committed 1 year ago

Commit 30b49cf1 parent c69912c6 files · +35 −20Browse files

Unified · Split

6 files
  1. Cargo.lock +1 −0
  2. crates/util/src/paths.rs +20 −18
  3. crates/zed/Cargo.toml +1 −0
  4. docs/src/development.md +6 −0
  5. tooling/perf/src/lib.rs +3 −1
  6. tooling/perf/src/main.rs +4 −1
Cargo.lock+1−0
@@ -20315,6 +20315,7 @@ dependencies = [ · 20314 unmodified lines
2031520315 "url",
2031620316 "urlencoding",
2031720317 "util",
20318+ "util_macros",
2031820319 "uuid",
2031920320 "vim",
2032020321 "vim_mode_setting",
crates/util/src/paths.rs+20−18
@@ -858,8 +858,9 @@ pub fn compare_paths( · 857 unmodified lines
858858 #[cfg(test)]
859859 mod tests {
860860 use super::*;
861+ use util_macros::perf;
861862
862− #[test]
863+ #[perf]
863864 fn compare_paths_with_dots() {
864865 let mut paths = vec![
865866 (Path::new("test_dirs"), false),
@@ -897,7 +898,7 @@ mod tests { · 31 unmodified lines
897898 );
898899 }
899900
900− #[test]
901+ #[perf]
901902 fn compare_paths_with_same_name_different_extensions() {
902903 let mut paths = vec![
903904 (Path::new("test_dirs/file.rs"), true),
@@ -919,7 +920,7 @@ mod tests { · 15 unmodified lines
919920 );
920921 }
921922
922− #[test]
923+ #[perf]
923924 fn compare_paths_case_semi_sensitive() {
924925 let mut paths = vec![
925926 (Path::new("test_DIRS"), false),
@@ -951,7 +952,7 @@ mod tests { · 25 unmodified lines
951952 );
952953 }
953954
954− #[test]
955+ #[perf]
955956 fn path_with_position_parse_posix_path() {
956957 // Test POSIX filename edge cases
957958 // Read more at https://en.wikipedia.org/wiki/Filename
@@ -1038,7 +1039,7 @@ mod tests { · 80 unmodified lines
10381039 );
10391040 }
10401041
1041− #[test]
1042+ #[perf]
10421043 #[cfg(not(target_os = "windows"))]
10431044 fn path_with_position_parse_posix_path_with_suffix() {
10441045 assert_eq!(
@@ -1094,7 +1095,7 @@ mod tests { · 49 unmodified lines
10941095 );
10951096 }
10961097
1097− #[test]
1098+ #[perf]
10981099 #[cfg(target_os = "windows")]
10991100 fn path_with_position_parse_windows_path() {
11001101 assert_eq!(
@@ -1116,7 +1117,7 @@ mod tests { · 15 unmodified lines
11161117 );
11171118 }
11181119
1119− #[test]
1120+ #[perf]
11201121 #[cfg(target_os = "windows")]
11211122 fn path_with_position_parse_windows_path_with_suffix() {
11221123 assert_eq!(
@@ -1229,7 +1230,7 @@ mod tests { · 106 unmodified lines
12291230 );
12301231 }
12311232
1232− #[test]
1233+ #[perf]
12331234 fn test_path_compact() {
12341235 let path: PathBuf = [
12351236 home_dir().to_string_lossy().to_string(),
@@ -1244,7 +1245,7 @@ mod tests { · 8 unmodified lines
12441245 }
12451246 }
12461247
1247− #[test]
1248+ #[perf]
12481249 fn test_extension_or_hidden_file_name() {
12491250 // No dots in name
12501251 let path = Path::new("/a/b/c/file_name.rs");
@@ -1267,7 +1268,7 @@ mod tests { · 16 unmodified lines
12671268 assert_eq!(path.extension_or_hidden_file_name(), Some("eslintrc.js"));
12681269 }
12691270
1270− #[test]
1271+ #[perf]
12711272 fn edge_of_glob() {
12721273 let path = Path::new("/work/node_modules");
12731274 let path_matcher =
@@ -1278,7 +1279,7 @@ mod tests { · 4 unmodified lines
12781279 );
12791280 }
12801281
1281− #[test]
1282+ #[perf]
12821283 fn project_search() {
12831284 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");
12841285 let path_matcher =
@@ -1289,7 +1290,7 @@ mod tests { · 4 unmodified lines
12891290 );
12901291 }
12911292
1292− #[test]
1293+ #[perf]
12931294 #[cfg(target_os = "windows")]
12941295 fn test_sanitized_path() {
12951296 let path = Path::new("C:\\Users\\someone\\test_file.rs");
@@ -1307,7 +1308,7 @@ mod tests { · 11 unmodified lines
13071308 );
13081309 }
13091310
1310− #[test]
1311+ #[perf]
13111312 fn test_compare_numeric_segments() {
13121313 // Helper function to create peekable iterators and test
13131314 fn compare(a: &str, b: &str) -> Ordering {
@@ -1375,7 +1376,7 @@ mod tests { · 61 unmodified lines
13751376 assert_eq!(b_iter.collect::<String>(), "def");
13761377 }
13771378
1378− #[test]
1379+ #[perf]
13791380 fn test_natural_sort() {
13801381 // Basic alphanumeric
13811382 assert_eq!(natural_sort("a", "b"), Ordering::Less);
@@ -1429,7 +1430,7 @@ mod tests { · 47 unmodified lines
14291430 assert_eq!(natural_sort("File_a1", "File_A1"), Ordering::Less);
14301431 }
14311432
1432− #[test]
1433+ #[perf]
14331434 fn test_compare_paths() {
14341435 // Helper function for cleaner tests
14351436 fn compare(a: &str, is_a_file: bool, b: &str, is_b_file: bool) -> Ordering {
@@ -1515,8 +1516,9 @@ mod tests { · 79 unmodified lines
15151516 );
15161517 }
15171518
1518− #[test]
1519+ #[perf]
15191520 fn test_natural_sort_case_sensitivity() {
1521+ std::thread::sleep(std::time::Duration::from_millis(100));
15201522 // Same letter different case - lowercase should come first
15211523 assert_eq!(natural_sort("a", "A"), Ordering::Less);
15221524 assert_eq!(natural_sort("A", "a"), Ordering::Greater);
@@ -1534,7 +1536,7 @@ mod tests { · 11 unmodified lines
15341536 assert_eq!(natural_sort("a", "B"), Ordering::Less);
15351537 }
15361538
1537− #[test]
1539+ #[perf]
15381540 fn test_natural_sort_with_numbers() {
15391541 // Basic number ordering
15401542 assert_eq!(natural_sort("file1", "file2"), Ordering::Less);
@@ -1612,7 +1614,7 @@ mod tests { · 71 unmodified lines
16121614 assert_eq!(natural_sort("file1", "File2"), Ordering::Less);
16131615 }
16141616
1615− #[test]
1617+ #[perf]
16161618 fn test_natural_sort_edge_cases() {
16171619 // Empty strings
16181620 assert_eq!(natural_sort("", ""), Ordering::Equal);
crates/zed/Cargo.toml+1−0
@@ -189,6 +189,7 @@ project = { workspace = true, features = ["test-support"] } · 188 unmodified lines
189189 terminal_view = { workspace = true, features = ["test-support"] }
190190 tree-sitter-md.workspace = true
191191 tree-sitter-rust.workspace = true
192+util_macros.workspace = true
192193 workspace = { workspace = true, features = ["test-support"] }
193194
194195 [package.metadata.bundle-dev]
docs/src/development.md+6−0
@@ -79,6 +79,12 @@ Here's a typical workflow for comparing frame rendering performance between diff · 78 unmodified lines
7979
8080 The `script/histogram` tool can accept as many measurement files as you like and will generate a histogram visualization comparing the frame rendering performance data between the provided versions.
8181
82+### Using `util_macros::perf`
83+
84+For benchmarking unit tests, annotate them with the `#[perf]` attribute from the `util_macros` crate. Then run `cargo
85+perf-test -p $CRATE` to benchmark them. See the rustdoc documentation on `crates/util_macros` and `tooling/perf` for
86+in-depth examples and explanations.
87+
8288 ## Contributor links
8389
8490 - [CONTRIBUTING.md](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md)
tooling/perf/src/lib.rs+3−1
@@ -1,5 +1,7 @@
11 //! Some constants and datatypes used in the Zed perf profiler. Should only be
22 //! consumed by the crate providing the matching macros.
3+//!
4+//! For usage documentation, see the docs on this crate's binary.
35
46 use collections::HashMap;
57 use serde::{Deserialize, Serialize};
@@ -274,7 +276,7 @@ impl Output { · 268 unmodified lines
274276 continue;
275277 };
276278 let shift =
277− (s_timings.iters_per_sec(s_iters) / o_timings.iters_per_sec(o_iters)) - 1.;
279+ (o_timings.iters_per_sec(o_iters) / s_timings.iters_per_sec(s_iters)) - 1.;
278280 if shift > max {
279281 max = shift;
280282 }
tooling/perf/src/main.rs+4−1
@@ -218,7 +218,10 @@ fn compare_profiles(args: &[String]) { · 217 unmodified lines
218218 let ident_new = args.first().expect("FATAL: missing identifier for new run");
219219 let ident_old = args.get(1).expect("FATAL: missing identifier for old run");
220220 let wspace_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
221− let runs_dir = PathBuf::from(&wspace_dir).join(consts::RUNS_DIR);
221+ let runs_dir = PathBuf::from(&wspace_dir)
222+ .join("..")
223+ .join("..")
224+ .join(consts::RUNS_DIR);
222225
223226 // Use the blank outputs initially, so we can merge into these with prefixes.
224227 let mut outputs_new = Output::blank();