Skip to content

Commit 3d5ec44

Browse files
committed
SPMI: Avoid duplicate example diffs in diffs summary
This deduplicates the examples that can be picked by their method name; this means that the examples no longer should show multiple example diffs with the same name.
1 parent 39111b0 commit 3d5ec44

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/coreclr/scripts/superpmi.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ def aggregate_diff_metrics(details_file):
19541954
# Project out these fields for the saved diffs, to use for further
19551955
# processing. Saving everything into memory is costly on memory when there
19561956
# are a large number of diffs.
1957-
diffs_fields = ["Context", "Context size", "Base ActualCodeBytes", "Diff ActualCodeBytes", "Base PerfScore", "Diff PerfScore"]
1957+
diffs_fields = ["Context", "Method full name", "Context size", "Base ActualCodeBytes", "Diff ActualCodeBytes", "Base PerfScore", "Diff PerfScore"]
19581958
diffs = []
19591959

19601960
for row in read_csv(details_file):
@@ -2725,12 +2725,22 @@ def diff_pct(r):
27252725

27262726
display_subset("Smallest {} zero sized diffs:", smallest_zero_size_contexts)
27272727

2728-
by_diff_size_pct_examples = [diff for diff in by_diff_size_pct if abs(int(diff['Diff ActualCodeBytes']) - int(diff['Base ActualCodeBytes'])) < 50]
2729-
if len(by_diff_size_pct_examples) == 0:
2730-
by_diff_size_pct_examples = by_diff_size_pct
2728+
# Prefer to show small diffs over large percentage wise diffs; sort by this additionally.
2729+
# sorted is stable, so for multiple small diffs this will keep them in order of percentage wise improvement/regression.
2730+
def is_small_diff(row):
2731+
if abs(int(row['Diff ActualCodeBytes']) - int(row['Base ActualCodeBytes'])) < 50:
2732+
return 0
2733+
2734+
return 1
2735+
2736+
by_small_then_improvement = sorted(by_diff_size_pct, key=is_small_diff)
2737+
by_small_then_regression = sorted(reversed(by_diff_size_pct), key=is_small_diff)
2738+
2739+
example_improvements = by_small_then_improvement[:3]
2740+
2741+
example_improvement_contexts = set(row["Context"] for row in example_improvements)
2742+
example_regressions = [row for row in by_small_then_regression if row["Context"] not in example_improvement_contexts][:3]
27312743

2732-
example_improvements = by_diff_size_pct_examples[:3]
2733-
example_regressions = by_diff_size_pct_examples[3:][-3:]
27342744
contexts = smallest_contexts + top_improvements + top_regressions + top_improvements_pct + top_regressions_pct + smallest_zero_size_contexts + example_improvements + example_regressions
27352745
examples = example_improvements + example_regressions
27362746

0 commit comments

Comments
 (0)