Skip to content

Commit f1de7df

Browse files
fix(report): sort diff table by absolute delta descending
The diff table previously sorted function names alphabetically, which buried the most significant changes. Sort by absolute self-time delta descending so the biggest changes appear at the top, directly answering "what changed the most?"
1 parent 85d4856 commit f1de7df

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/report.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,22 @@ pub fn diff_runs(a: &Run, b: &Run, label_a: &str, label_b: &str) -> String {
573573
let a_map: HashMap<&str, &FnEntry> = a.functions.iter().map(|f| (f.name.as_str(), f)).collect();
574574
let b_map: HashMap<&str, &FnEntry> = b.functions.iter().map(|f| (f.name.as_str(), f)).collect();
575575

576-
// Collect all function names, sorted for deterministic output.
576+
// Collect unique function names, sorted by absolute self-time delta descending
577+
// so the biggest changes appear first.
577578
let mut names: Vec<&str> = a_map.keys().chain(b_map.keys()).copied().collect();
578579
names.sort_unstable();
579580
names.dedup();
581+
names.sort_by(|na, nb| {
582+
let delta_a = (b_map.get(na).map_or(0.0, |e| e.self_ms)
583+
- a_map.get(na).map_or(0.0, |e| e.self_ms))
584+
.abs();
585+
let delta_b = (b_map.get(nb).map_or(0.0, |e| e.self_ms)
586+
- a_map.get(nb).map_or(0.0, |e| e.self_ms))
587+
.abs();
588+
delta_b
589+
.partial_cmp(&delta_a)
590+
.unwrap_or(std::cmp::Ordering::Equal)
591+
});
580592

581593
// Check if either run has alloc data or CPU data.
582594
let has_allocs = a.functions.iter().any(|f| f.alloc_count > 0)

0 commit comments

Comments
 (0)