Skip to content

Commit 4030e01

Browse files
authored
fix: ignore zero-byte benchmark file identities (#9197)
Fixes file-size reporting when either the baseline or HEAD records an empty file. The report previously dropped the zero-byte row and then treated its missing counterpart as `0 B`, which could report a false deletion or a newly created file. File identities with a zero-byte record on either side are now excluded from both sides before totals and missing-file comparisons. The regression test covers both asymmetric cases. Checks: `uv run --no-project --with orjson --with pandas pytest scripts/tests/test_benchmark_reporting.py` and `ruff check scripts/compare-benchmark-jsons.py scripts/tests/test_benchmark_reporting.py`. Signed-off-by: Connor Tsui <[email protected]>
1 parent 12f7fea commit 4030e01

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

‎scripts/compare-benchmark-jsons.py‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,15 @@ def format_pct_change(pct: float) -> str:
614614
return f"{sign}{pct:.1f}%"
615615

616616

617-
def extract_file_size_data(df: pd.DataFrame) -> dict[tuple[str, str, str, str], int]:
618-
"""Extract file-size rows keyed by benchmark, scale factor, format, and file."""
617+
def extract_file_size_data(
618+
df: pd.DataFrame,
619+
) -> tuple[dict[tuple[str, str, str, str], int], set[tuple[str, str, str, str]]]:
620+
"""Extract file-size rows and the identities explicitly ignored for being empty."""
619621

620622
data = {}
623+
ignored = set()
621624
if df.empty:
622-
return data
625+
return data, ignored
623626

624627
for _, row in df.iterrows():
625628
metadata = row.get("file_size")
@@ -635,19 +638,26 @@ def extract_file_size_data(df: pd.DataFrame) -> dict[tuple[str, str, str, str],
635638
value = row.get("value")
636639
if pd.isna(value):
637640
continue
638-
data[key] = int(value)
641+
size = int(value)
642+
if size == 0:
643+
ignored.add(key)
644+
continue
645+
data[key] = size
639646

640-
return data
647+
return data, ignored
641648

642649

643650
def format_file_size_report(base_rows: pd.DataFrame, pr_rows: pd.DataFrame) -> str:
644651
"""Render a shared-comment file-size comparison report."""
645652

646-
pr_data = extract_file_size_data(pr_rows)
653+
pr_data, pr_ignored = extract_file_size_data(pr_rows)
654+
base_data, base_ignored = extract_file_size_data(base_rows)
655+
ignored = base_ignored | pr_ignored
656+
pr_data = {key: value for key, value in pr_data.items() if key not in ignored}
647657
if not pr_data:
648658
return ""
649659

650-
base_data = extract_file_size_data(base_rows)
660+
base_data = {key: value for key, value in base_data.items() if key not in ignored}
651661
pr_scopes = {(benchmark, scale_factor) for benchmark, scale_factor, _file_format, _file_name in pr_data}
652662
base_data = {key: value for key, value in base_data.items() if key[:2] in pr_scopes}
653663
if not base_data:

‎scripts/tests/test_benchmark_reporting.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,31 @@ def test_file_size_report_reads_shared_benchmark_rows() -> None:
413413
assert "| part-0.vortex | 10 | vortex-file-compressed | 100 B | 125 B | +25 B | +25.0% |" in report
414414

415415

416+
def test_file_size_report_ignores_file_identities_with_a_zero_byte_side() -> None:
417+
compare = load_compare_module()
418+
419+
report = compare.format_file_size_report(
420+
pd.DataFrame(
421+
[
422+
file_size_record_for("base-sha", 100, "tpch", "10", "vortex-file-compressed", "head-empty"),
423+
file_size_record_for("base-sha", 0, "tpch", "10", "vortex-file-compressed", "base-empty"),
424+
file_size_record_for("base-sha", 100, "tpch", "10", "vortex-file-compressed", "changed"),
425+
]
426+
),
427+
pd.DataFrame(
428+
[
429+
file_size_record_for("pr-sha", 0, "tpch", "10", "vortex-file-compressed", "head-empty"),
430+
file_size_record_for("pr-sha", 125, "tpch", "10", "vortex-file-compressed", "base-empty"),
431+
file_size_record_for("pr-sha", 125, "tpch", "10", "vortex-file-compressed", "changed"),
432+
]
433+
),
434+
)
435+
436+
assert "<summary>File Size Changes (1 files changed, +25.0% overall, 1↑ 0↓)</summary>" in report
437+
assert "head-empty" not in report
438+
assert "base-empty" not in report
439+
440+
416441
def test_file_size_report_ignores_baseline_rows_outside_pr_scope() -> None:
417442
compare = load_compare_module()
418443

0 commit comments

Comments
 (0)