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
20315 "url",20315 "url",
20316 "urlencoding",20316 "urlencoding",
20317 "util",20317 "util",
20318 "util_macros",
20318 "uuid",20319 "uuid",
20319 "vim",20320 "vim",
20320 "vim_mode_setting",20321 "vim_mode_setting",
crates/util/src/paths.rs+20−18
@@ -858,8 +858,9 @@ pub fn compare_paths( · 857 unmodified lines
858#[cfg(test)]858#[cfg(test)]
859mod tests {859mod tests {
860 use super::*;860 use super::*;
861 use util_macros::perf;
861 862
862 #[test]863 #[perf]
863 fn compare_paths_with_dots() {864 fn compare_paths_with_dots() {
864 let mut paths = vec![865 let mut paths = vec![
865 (Path::new("test_dirs"), false),866 (Path::new("test_dirs"), false),
@@ -897,7 +898,7 @@ mod tests { · 31 unmodified lines
897 );898 );
898 }899 }
899 900
900 #[test]901 #[perf]
901 fn compare_paths_with_same_name_different_extensions() {902 fn compare_paths_with_same_name_different_extensions() {
902 let mut paths = vec![903 let mut paths = vec![
903 (Path::new("test_dirs/file.rs"), true),904 (Path::new("test_dirs/file.rs"), true),
@@ -919,7 +920,7 @@ mod tests { · 15 unmodified lines
919 );920 );
920 }921 }
921 922
922 #[test]923 #[perf]
923 fn compare_paths_case_semi_sensitive() {924 fn compare_paths_case_semi_sensitive() {
924 let mut paths = vec![925 let mut paths = vec![
925 (Path::new("test_DIRS"), false),926 (Path::new("test_DIRS"), false),
@@ -951,7 +952,7 @@ mod tests { · 25 unmodified lines
951 );952 );
952 }953 }
953 954
954 #[test]955 #[perf]
955 fn path_with_position_parse_posix_path() {956 fn path_with_position_parse_posix_path() {
956 // Test POSIX filename edge cases957 // Test POSIX filename edge cases
957 // Read more at https://en.wikipedia.org/wiki/Filename958 // Read more at https://en.wikipedia.org/wiki/Filename
@@ -1038,7 +1039,7 @@ mod tests { · 80 unmodified lines
1038 );1039 );
1039 }1040 }
1040 1041
1041 #[test]1042 #[perf]
1042 #[cfg(not(target_os = "windows"))]1043 #[cfg(not(target_os = "windows"))]
1043 fn path_with_position_parse_posix_path_with_suffix() {1044 fn path_with_position_parse_posix_path_with_suffix() {
1044 assert_eq!(1045 assert_eq!(
@@ -1094,7 +1095,7 @@ mod tests { · 49 unmodified lines
1094 );1095 );
1095 }1096 }
1096 1097
1097 #[test]1098 #[perf]
1098 #[cfg(target_os = "windows")]1099 #[cfg(target_os = "windows")]
1099 fn path_with_position_parse_windows_path() {1100 fn path_with_position_parse_windows_path() {
1100 assert_eq!(1101 assert_eq!(
@@ -1116,7 +1117,7 @@ mod tests { · 15 unmodified lines
1116 );1117 );
1117 }1118 }
1118 1119
1119 #[test]1120 #[perf]
1120 #[cfg(target_os = "windows")]1121 #[cfg(target_os = "windows")]
1121 fn path_with_position_parse_windows_path_with_suffix() {1122 fn path_with_position_parse_windows_path_with_suffix() {
1122 assert_eq!(1123 assert_eq!(
@@ -1229,7 +1230,7 @@ mod tests { · 106 unmodified lines
1229 );1230 );
1230 }1231 }
1231 1232
1232 #[test]1233 #[perf]
1233 fn test_path_compact() {1234 fn test_path_compact() {
1234 let path: PathBuf = [1235 let path: PathBuf = [
1235 home_dir().to_string_lossy().to_string(),1236 home_dir().to_string_lossy().to_string(),
@@ -1244,7 +1245,7 @@ mod tests { · 8 unmodified lines
1244 }1245 }
1245 }1246 }
1246 1247
1247 #[test]1248 #[perf]
1248 fn test_extension_or_hidden_file_name() {1249 fn test_extension_or_hidden_file_name() {
1249 // No dots in name1250 // No dots in name
1250 let path = Path::new("/a/b/c/file_name.rs");1251 let path = Path::new("/a/b/c/file_name.rs");
@@ -1267,7 +1268,7 @@ mod tests { · 16 unmodified lines
1267 assert_eq!(path.extension_or_hidden_file_name(), Some("eslintrc.js"));1268 assert_eq!(path.extension_or_hidden_file_name(), Some("eslintrc.js"));
1268 }1269 }
1269 1270
1270 #[test]1271 #[perf]
1271 fn edge_of_glob() {1272 fn edge_of_glob() {
1272 let path = Path::new("/work/node_modules");1273 let path = Path::new("/work/node_modules");
1273 let path_matcher =1274 let path_matcher =
@@ -1278,7 +1279,7 @@ mod tests { · 4 unmodified lines
1278 );1279 );
1279 }1280 }
1280 1281
1281 #[test]1282 #[perf]
1282 fn project_search() {1283 fn project_search() {
1283 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");1284 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");
1284 let path_matcher =1285 let path_matcher =
@@ -1289,7 +1290,7 @@ mod tests { · 4 unmodified lines
1289 );1290 );
1290 }1291 }
1291 1292
1292 #[test]1293 #[perf]
1293 #[cfg(target_os = "windows")]1294 #[cfg(target_os = "windows")]
1294 fn test_sanitized_path() {1295 fn test_sanitized_path() {
1295 let path = Path::new("C:\\Users\\someone\\test_file.rs");1296 let path = Path::new("C:\\Users\\someone\\test_file.rs");
@@ -1307,7 +1308,7 @@ mod tests { · 11 unmodified lines
1307 );1308 );
1308 }1309 }
1309 1310
1310 #[test]1311 #[perf]
1311 fn test_compare_numeric_segments() {1312 fn test_compare_numeric_segments() {
1312 // Helper function to create peekable iterators and test1313 // Helper function to create peekable iterators and test
1313 fn compare(a: &str, b: &str) -> Ordering {1314 fn compare(a: &str, b: &str) -> Ordering {
@@ -1375,7 +1376,7 @@ mod tests { · 61 unmodified lines
1375 assert_eq!(b_iter.collect::<String>(), "def");1376 assert_eq!(b_iter.collect::<String>(), "def");
1376 }1377 }
1377 1378
1378 #[test]1379 #[perf]
1379 fn test_natural_sort() {1380 fn test_natural_sort() {
1380 // Basic alphanumeric1381 // Basic alphanumeric
1381 assert_eq!(natural_sort("a", "b"), Ordering::Less);1382 assert_eq!(natural_sort("a", "b"), Ordering::Less);
@@ -1429,7 +1430,7 @@ mod tests { · 47 unmodified lines
1429 assert_eq!(natural_sort("File_a1", "File_A1"), Ordering::Less);1430 assert_eq!(natural_sort("File_a1", "File_A1"), Ordering::Less);
1430 }1431 }
1431 1432
1432 #[test]1433 #[perf]
1433 fn test_compare_paths() {1434 fn test_compare_paths() {
1434 // Helper function for cleaner tests1435 // Helper function for cleaner tests
1435 fn compare(a: &str, is_a_file: bool, b: &str, is_b_file: bool) -> Ordering {1436 fn compare(a: &str, is_a_file: bool, b: &str, is_b_file: bool) -> Ordering {
@@ -1515,8 +1516,9 @@ mod tests { · 79 unmodified lines
1515 );1516 );
1516 }1517 }
1517 1518
1518 #[test]1519 #[perf]
1519 fn test_natural_sort_case_sensitivity() {1520 fn test_natural_sort_case_sensitivity() {
1521 std::thread::sleep(std::time::Duration::from_millis(100));
1520 // Same letter different case - lowercase should come first1522 // Same letter different case - lowercase should come first
1521 assert_eq!(natural_sort("a", "A"), Ordering::Less);1523 assert_eq!(natural_sort("a", "A"), Ordering::Less);
1522 assert_eq!(natural_sort("A", "a"), Ordering::Greater);1524 assert_eq!(natural_sort("A", "a"), Ordering::Greater);
@@ -1534,7 +1536,7 @@ mod tests { · 11 unmodified lines
1534 assert_eq!(natural_sort("a", "B"), Ordering::Less);1536 assert_eq!(natural_sort("a", "B"), Ordering::Less);
1535 }1537 }
1536 1538
1537 #[test]1539 #[perf]
1538 fn test_natural_sort_with_numbers() {1540 fn test_natural_sort_with_numbers() {
1539 // Basic number ordering1541 // Basic number ordering
1540 assert_eq!(natural_sort("file1", "file2"), Ordering::Less);1542 assert_eq!(natural_sort("file1", "file2"), Ordering::Less);
@@ -1612,7 +1614,7 @@ mod tests { · 71 unmodified lines
1612 assert_eq!(natural_sort("file1", "File2"), Ordering::Less);1614 assert_eq!(natural_sort("file1", "File2"), Ordering::Less);
1613 }1615 }
1614 1616
1615 #[test]1617 #[perf]
1616 fn test_natural_sort_edge_cases() {1618 fn test_natural_sort_edge_cases() {
1617 // Empty strings1619 // Empty strings
1618 assert_eq!(natural_sort("", ""), Ordering::Equal);1620 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
189terminal_view = { workspace = true, features = ["test-support"] }189terminal_view = { workspace = true, features = ["test-support"] }
190tree-sitter-md.workspace = true190tree-sitter-md.workspace = true
191tree-sitter-rust.workspace = true191tree-sitter-rust.workspace = true
192util_macros.workspace = true
192workspace = { workspace = true, features = ["test-support"] }193workspace = { workspace = true, features = ["test-support"] }
193 194
194[package.metadata.bundle-dev]195[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
79 79
80The `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.80The `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.
81 81
82### Using `util_macros::perf`
83
84For benchmarking unit tests, annotate them with the `#[perf]` attribute from the `util_macros` crate. Then run `cargo
85perf-test -p $CRATE` to benchmark them. See the rustdoc documentation on `crates/util_macros` and `tooling/perf` for
86in-depth examples and explanations.
87
82## Contributor links88## Contributor links
83 89
84- [CONTRIBUTING.md](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md)90- [CONTRIBUTING.md](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md)
tooling/perf/src/lib.rs+3−1
@@ -1,5 +1,7 @@
1//! Some constants and datatypes used in the Zed perf profiler. Should only be1//! Some constants and datatypes used in the Zed perf profiler. Should only be
2//! consumed by the crate providing the matching macros.2//! consumed by the crate providing the matching macros.
3//!
4//! For usage documentation, see the docs on this crate's binary.
3 5
4use collections::HashMap;6use collections::HashMap;
5use serde::{Deserialize, Serialize};7use serde::{Deserialize, Serialize};
@@ -274,7 +276,7 @@ impl Output { · 268 unmodified lines
274 continue;276 continue;
275 };277 };
276 let shift =278 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.;
278 if shift > max {280 if shift > max {
279 max = shift;281 max = shift;
280 }282 }
tooling/perf/src/main.rs+4−1
@@ -218,7 +218,10 @@ fn compare_profiles(args: &[String]) { · 217 unmodified lines
218 let ident_new = args.first().expect("FATAL: missing identifier for new run");218 let ident_new = args.first().expect("FATAL: missing identifier for new run");
219 let ident_old = args.get(1).expect("FATAL: missing identifier for old run");219 let ident_old = args.get(1).expect("FATAL: missing identifier for old run");
220 let wspace_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();220 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);
222 225
223 // Use the blank outputs initially, so we can merge into these with prefixes.226 // Use the blank outputs initially, so we can merge into these with prefixes.
224 let mut outputs_new = Output::blank();227 let mut outputs_new = Output::blank();