From 9a51e117ef95e9479b80e12dcde54072b5822cc8 Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 20 Nov 2026 09:51:52 -0500 Subject: [PATCH 1/4] Show SQL benchmark comments as one row per query The PR benchmark comment split SQL results into one folded table per engine and format, each cell reading `PR / base / %diff`, so comparing targets on a query meant opening several tables. SQL queries now share one table: a row per query, a column per target such as `datafusion:vortex`, each cell `PR time (PR/base)` in a readable unit, bold and marked once it clears the suite's threshold, under a geomean row. Cold runs get the same table, folded. Random-access and compression results keep their existing tables. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Nicholas Gates --- scripts/compare-benchmark-jsons.py | 163 +++++++++++++++++++++- scripts/tests/test_benchmark_reporting.py | 89 ++++++++---- 2 files changed, 223 insertions(+), 29 deletions(-) diff --git a/scripts/compare-benchmark-jsons.py b/scripts/compare-benchmark-jsons.py index 77d9ae9bddd..56e03150400 100644 --- a/scripts/compare-benchmark-jsons.py +++ b/scripts/compare-benchmark-jsons.py @@ -65,6 +65,10 @@ FORMAT_DISPLAY_NAMES = { "vortex": "vortex-file-compressed", } +# Query table columns use the short format names targets are declared with. +FORMAT_COLUMN_NAMES = { + "vortex-file-compressed": "vortex", +} @dataclass @@ -703,6 +707,135 @@ def format_delta_cell( return f"{pr_text} / {base_text} / {change_text} {marker}" +def format_duration(value_ns: object) -> str: + """Render a nanosecond duration with three significant figures in a readable unit.""" + + if pd.isna(value_ns): + return "โ€”" + value = float(value_ns) + for scale, unit in ((1e9, "s"), (1e6, "ms"), (1e3, "ยตs")): + if abs(value) >= scale: + value /= scale + break + else: + unit = "ns" + if abs(value) >= 100: + return f"{value:.0f} {unit}" + if abs(value) >= 10: + return f"{value:.1f} {unit}" + return f"{value:.2f} {unit}" + + +def format_query_cell( + pr_value: object, ratio: object, improvement_threshold: float, regression_threshold: float +) -> str: + """Render one query cell as `PR time (PR/base)`, bold and marked once it clears the threshold.""" + + if pd.isna(pr_value): + return "โ€”" + duration = format_duration(pr_value) + if pd.isna(ratio) or float(ratio) <= 0: + return duration + cell = f"{duration} ({float(ratio):.2f})" + marker = format_change_marker(float(ratio), improvement_threshold, regression_threshold) + return f"**{cell}** {marker}" if marker else cell + + +def is_sql_query(query: object) -> bool: + """Return whether a row's query is a SQL query number, not a random-access variant.""" + + return isinstance(query, (int, np.integer)) and not isinstance(query, bool) + + +def query_column_label(engine: str, file_format: str) -> str: + """Name a query table column the way targets are named, e.g. `datafusion:vortex`.""" + + for full_name, short_name in FORMAT_COLUMN_NAMES.items(): + if file_format == full_name or file_format.startswith(f"{full_name} "): + file_format = short_name + file_format[len(full_name) :] + break + return f"{engine}:{file_format}" + + +def query_column_sort_key(combo: tuple[str, str]) -> tuple[int, int, str, str]: + """Order query table columns by engine, then format, with a format's variants beside it. + + A variant such as `vortex-file-compressed [scan-api]` sorts right after its base format. + """ + + engine, file_format = combo + base_format = file_format.split(" [", 1)[0] + return ( + ENGINE_ORDER.get(engine, len(ENGINE_ORDER)), + FILE_FORMAT_ORDER.get(base_format, len(FILE_FORMAT_ORDER)), + engine, + file_format, + ) + + +def format_query_table( + df: pd.DataFrame, + run: str, + improvement_threshold: float, + regression_threshold: float, +) -> str | None: + """Render one row per query and one column per target, with a geomean row first. + + Each cell is the PR's `run` ("hot" or "cold") time and its ratio to the base; the + geomean row holds the geomean time and the geomean ratio over the queries with a base. + """ + + value_column = f"{run}_value_pr" + ratio_column = "ratio" if run == "hot" else "cold_ratio" + rows = df[df[value_column].notna()].copy() + if rows.empty: + return None + + rows["row_label"] = rows["name"].map(lambda name: str(name).rsplit("/", 1)[0]) + row_keys = ["row_label"] + for extra in ("storage", "dataset_key"): + if rows[extra].astype(str).nunique() > 1: + row_keys.append(extra) + combos = sorted( + {(str(engine), str(file_format)) for engine, file_format in zip(rows["engine"], rows["file_format"])}, + key=query_column_sort_key, + ) + + def cell(value: object, ratio: object) -> str: + return format_query_cell(value, ratio, improvement_threshold, regression_threshold) + + geomean_cells = [] + for engine, file_format in combos: + target_rows = rows[(rows["engine"] == engine) & (rows["file_format"] == file_format)] + geomean_cells.append( + cell( + geometric_mean_from_values(target_rows[value_column]), + calculate_geometric_mean(target_rows, ratio_column), + ) + ) + + table_rows = [["**geomean**", *geomean_cells]] + for key, group in sorted(rows.groupby(row_keys, sort=False), key=lambda item: tuple(str(k) for k in item[0])): + key = key if isinstance(key, tuple) else (key,) + label = str(key[0]) + "".join(f" ({part})" for part in key[1:] if part is not None and str(part) != "nan") + cells = [] + for engine, file_format in combos: + match = group[(group["engine"] == engine) & (group["file_format"] == file_format)] + if match.empty: + cells.append("โ€”") + else: + cells.append(cell(match[value_column].iloc[0], match[ratio_column].iloc[0])) + table_rows.append([label, *cells]) + + headers = ["query", *(query_column_label(engine, file_format) for engine, file_format in combos)] + return pd.DataFrame(table_rows, columns=headers).to_markdown( + index=False, + tablefmt="github", + disable_numparse=True, + colalign=("left", *("right" for _ in combos)), + ) + + def format_comparison_ratio(value: float) -> str: """Render a PR/base ratio or identify an unmatched PR measurement.""" @@ -1026,10 +1159,12 @@ def format_report_help() -> str: "first-run cost per row, and `hot/cold` is how much of " "each run the warm path saves. Rows whose results predate per-run reporting " "show only one value, taken from the value the runner reported.", - "- **Table cells**: Each cell reads `PR / base / %diff`. The hot and cold " - "columns mark a change as ๐Ÿ”ด slower or ๐ŸŸข faster once it clears this suite's " - "threshold; anything smaller is noise here and is left unmarked, as is " - "`hot/cold`, because a shift in the warm-up ratio is not a win or a loss by itself.", + "- **Query tables**: One row per query and one column per target. Each cell " + "reads `PR time (PR/base)`, so `0.80` is 20% faster. A change that clears this " + "suite's threshold is bold and marked ๐Ÿ”ด slower or ๐ŸŸข faster; anything smaller is " + "noise here and is left plain. The `geomean` row holds the geomean time and the " + "geomean ratio. Hot runs are shown first and cold runs are folded below them.", + "- **Other tables**: Each cell reads `PR / base / %diff`, marked the same way.", "", "", ] @@ -1199,7 +1334,25 @@ def main() -> None: print("---") print("") - grouped_tables = df3.groupby(["engine", "file_format", "unit"], dropna=False, sort=False) + sql_mask = df3["query"].map(is_sql_query) & df3["unit"].eq("ns") + sql_df = df3[sql_mask] + hot_table = format_query_table(sql_df, "hot", improvement_threshold, regression_threshold) + if hot_table is not None: + print(hot_table) + print("") + cold_table = format_query_table(sql_df, "cold", improvement_threshold, regression_threshold) + if cold_table is not None: + print("
") + print("Cold runs (first iteration)") + print("") + print("
") + print("") + print(cold_table) + print("") + print("
") + print("") + + grouped_tables = df3[~sql_mask].groupby(["engine", "file_format", "unit"], dropna=False, sort=False) for engine, file_format, unit in sorted(grouped_tables.groups.keys(), key=group_sort_key): group_df = grouped_tables.get_group((engine, file_format, unit)).sort_values("name") group_performance = format_performance( diff --git a/scripts/tests/test_benchmark_reporting.py b/scripts/tests/test_benchmark_reporting.py index 49712ef9991..7f54d646f17 100644 --- a/scripts/tests/test_benchmark_reporting.py +++ b/scripts/tests/test_benchmark_reporting.py @@ -195,9 +195,17 @@ def render_report( return result.stdout +def markdown_rows(report: str, name: str) -> list[list[str]]: + """Return every Markdown table row whose first cell is `name`, in report order.""" + return [ + [cell.strip() for cell in line.strip("|").split("|")] + for line in report.splitlines() + if line.startswith(f"| {name} ") + ] + + def markdown_row(report: str, name: str) -> list[str]: - line = next(line for line in report.splitlines() if line.startswith(f"| {name} ")) - return [cell.strip() for cell in line.strip("|").split("|")] + return markdown_rows(report, name)[0] def test_within_engine_analysis_uses_each_engines_own_parquet_control() -> None: @@ -348,9 +356,11 @@ def test_comparison_report_retains_sql_analysis(tmp_path: Path) -> None: assert "**Vortex (geomean)**: hot " in report assert "**Parquet (geomean)**: hot " in report assert "How to read Verdict and Engines" in report - assert "datafusion / vortex-file-compressed / ns " in report - assert "datafusion / parquet / ns " in report - assert "unknown / unknown" not in report + # SQL queries share one table, with a row per query and a column per target. + assert markdown_row(report, "query") == ["query", "datafusion:vortex", "datafusion:parquet"] + assert markdown_row(report, "tpch_q01") == ["tpch_q01", "**70.0 ns (0.88)** ๐ŸŸข", "105 ns (1.05)"] + assert "datafusion / " not in report + assert "unknown" not in report def test_large_hot_medians_render_without_scientific_notation() -> None: @@ -397,9 +407,11 @@ def test_only_changes_past_the_suite_threshold_are_marked(tmp_path: Path) -> Non report = render_report(tmp_path, base_rows, pr_rows, "TPC-H") - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed")[1] == "109 / 100 / +9.0%" - assert markdown_row(report, "tpch_q02/datafusion:vortex-file-compressed")[1] == "111 / 100 / +11.0% ๐Ÿ”ด" - assert markdown_row(report, "tpch_q03/datafusion:vortex-file-compressed")[1] == "89 / 100 / -11.0% ๐ŸŸข" + assert markdown_row(report, "tpch_q01")[1] == "109 ns (1.09)" + assert markdown_row(report, "tpch_q02")[1] == "**111 ns (1.11)** ๐Ÿ”ด" + assert markdown_row(report, "tpch_q03")[1] == "**89.0 ns (0.89)** ๐ŸŸข" + # The geomean row leads the table: geomean time and geomean ratio. + assert markdown_row(report, "**geomean**")[1] == "102 ns (1.02)" def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: @@ -426,13 +438,11 @@ def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: report = render_report(tmp_path, base_rows, pr_rows, "TPC-H") - # The marks sit on the numbers that moved, not on the benchmark name. - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed") == [ - "tpch_q01/datafusion:vortex-file-compressed", - "50 / 100 / -50.0% ๐ŸŸข", - "2000 / 1000 / +100.0% ๐Ÿ”ด", - "0.03 / 0.10 / -75.0%", - ] + # Hot runs come first; cold runs follow in their own folded table. + hot, cold = markdown_rows(report, "tpch_q01") + assert hot == ["tpch_q01", "**50.0 ns (0.50)** ๐ŸŸข", "100 ns (1.00)"] + assert cold == ["tpch_q01", "**2.00 ยตs (2.00)** ๐Ÿ”ด", "1.00 ยตs (1.00)"] + assert "Cold runs (first iteration)" in report assert "**Attributed Vortex impact**: -50.0%" in report assert "**Vortex (geomean)**: hot 0.500x โœ… ยท cold 2.000x โŒ" in report assert "**Parquet (geomean)**: hot 1.000x โž– ยท cold 1.000x โž–" in report @@ -465,12 +475,9 @@ def test_verdict_ignores_a_cold_start_only_regression(tmp_path: Path) -> None: assert "**Attributed Vortex impact**: +0.0%" in report assert "**Vortex (geomean)**: hot 1.000x โž– ยท cold 4.000x โŒ" in report - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed") == [ - "tpch_q01/datafusion:vortex-file-compressed", - "100 / 100 / +0.0%", - "400 / 100 / +300.0% ๐Ÿ”ด", - "0.25 / 1.00 / -75.0%", - ] + hot, cold = markdown_rows(report, "tpch_q01") + assert hot[1] == "100 ns (1.00)" + assert cold[1] == "**400 ns (4.00)** ๐Ÿ”ด" def file_size_record(commit: str, size: int) -> dict[str, object]: @@ -793,7 +800,7 @@ def test_report_compares_ingest_records(tmp_path: Path) -> None: assert "**Engines**: DataFusion " in report assert "random-access " in report assert "ignored when records exist" not in report - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed")[1] == "70 / 80 / -12.5% ๐ŸŸข" + assert markdown_row(report, "tpch_q01")[1:] == ["**70.0 ns (0.88)** ๐ŸŸข", "105 ns (1.05)"] assert markdown_row(report, "random-access/taxi/uniform/parquet-cached")[1] == "105 / 100 / +5.0%" assert markdown_row(report, "random-access/taxi/uniform/lance-cached")[1] == "300 / โ€” / no baseline" assert "random-access / lance / ns " in report @@ -815,7 +822,7 @@ def test_report_compares_file_size_records_from_the_database(tmp_path: Path) -> report = render_report(tmp_path, base_records, pr_results, "TPC-H", pr_records) - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed")[1] == "80 / 80 / +0.0%" + assert markdown_row(report, "tpch_q01")[1] == "80.0 ns (1.00)" assert "File Size Changes (2 files changed, -16.7% overall, 1โ†‘ 1โ†“)" in report assert "| part-1.vortex | 10 | vortex-file-compressed | 50 B | 0 B | -50 B | -100.0% |" in report @@ -830,7 +837,7 @@ def test_report_handles_a_baseline_of_only_file_sizes(tmp_path: Path) -> None: report = render_report(tmp_path, base_records, pr_results, "TPC-H", pr_records) - assert markdown_row(report, "tpch_q01/datafusion:vortex-file-compressed")[1] == "80 / โ€” / no baseline" + assert markdown_row(report, "tpch_q01")[1] == "80.0 ns" assert "File Size Changes (1 files changed, +25.0% overall, 1โ†‘ 0โ†“)" in report @@ -954,3 +961,37 @@ def test_capture_file_sizes_reads_only_the_named_directory(tmp_path: Path) -> No records = [json.loads(line) for line in output_path.read_text(encoding="utf-8").splitlines()] assert [record["value"] for record in records] == [42] + + +def test_query_table_puts_a_format_variant_beside_its_base_format(tmp_path: Path) -> None: + targets = [ + ("duckdb", "vortex-file-compressed", 90, 90), + ("datafusion", "parquet", 100, 100), + ("datafusion", "vortex-file-compressed [scan-api]", 1_500_000, 1_200_000), + ("datafusion", "vortex-file-compressed", 80, 80), + ] + base = [query_record("base-sha", 1, engine, fmt, base) for engine, fmt, base, _pr in targets] + pr = [query_record("pr-sha", 1, engine, fmt, pr) for engine, fmt, _base, pr in targets] + pr_results = [stored_timing_row("pr-sha", "ignored when records exist", 1)] + + report = render_report(tmp_path, base, pr_results, "TPC-H", pr) + + assert markdown_row(report, "query") == [ + "query", + "datafusion:vortex", + "datafusion:vortex [scan-api]", + "datafusion:parquet", + "duckdb:vortex", + ] + assert markdown_row(report, "tpch_q01")[2] == "**1.20 ms (0.80)** ๐ŸŸข" + + +def test_format_duration_picks_a_readable_unit() -> None: + compare = load_compare_module() + + assert compare.format_duration(950) == "950 ns" + assert compare.format_duration(12_345) == "12.3 ยตs" + assert compare.format_duration(1_234_567) == "1.23 ms" + assert compare.format_duration(152_400_000) == "152 ms" + assert compare.format_duration(2_500_000_000) == "2.50 s" + assert compare.format_duration(float("nan")) == "โ€”" From de8920706a272e10012307c37dea434961ee74f0 Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 20 Nov 2026 09:58:21 -0500 Subject: [PATCH 2/4] Show develop and PR times in each query cell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bare PR time with a ratio did not say what it was compared with. Each cell now reads `develop โ†’ PR (PR รท develop)`, a caption names both commits, and the geomean row compares each target's geomeans. A note explains `[scan-api]` columns when one is present, and query numbers stored as floats still count as SQL queries. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Nicholas Gates --- scripts/compare-benchmark-jsons.py | 79 ++++++++++++++++++----- scripts/tests/test_benchmark_reporting.py | 56 ++++++++++++---- 2 files changed, 107 insertions(+), 28 deletions(-) diff --git a/scripts/compare-benchmark-jsons.py b/scripts/compare-benchmark-jsons.py index 56e03150400..147b1a8fc54 100644 --- a/scripts/compare-benchmark-jsons.py +++ b/scripts/compare-benchmark-jsons.py @@ -727,16 +727,30 @@ def format_duration(value_ns: object) -> str: def format_query_cell( - pr_value: object, ratio: object, improvement_threshold: float, regression_threshold: float + base_value: object, + pr_value: object, + ratio: object, + improvement_threshold: float, + regression_threshold: float, ) -> str: - """Render one query cell as `PR time (PR/base)`, bold and marked once it clears the threshold.""" + """Render one query cell as `develop โ†’ PR (PR/develop)`, bold and marked past the threshold. + + The unit is written once when both times share it, as in `131 โ†’ 118 ms (0.90)`. + """ if pd.isna(pr_value): return "โ€”" - duration = format_duration(pr_value) + pr_text = format_duration(pr_value) + if pd.isna(base_value): + return f"โ€” โ†’ {pr_text}" + base_text = format_duration(base_value) + base_number, base_unit = base_text.rsplit(" ", 1) + if pr_text.endswith(f" {base_unit}"): + base_text = base_number + cell = f"{base_text} โ†’ {pr_text}" if pd.isna(ratio) or float(ratio) <= 0: - return duration - cell = f"{duration} ({float(ratio):.2f})" + return cell + cell += f" ({float(ratio):.2f})" marker = format_change_marker(float(ratio), improvement_threshold, regression_threshold) return f"**{cell}** {marker}" if marker else cell @@ -744,7 +758,12 @@ def format_query_cell( def is_sql_query(query: object) -> bool: """Return whether a row's query is a SQL query number, not a random-access variant.""" - return isinstance(query, (int, np.integer)) and not isinstance(query, bool) + if isinstance(query, bool): + return False + if isinstance(query, (int, np.integer)): + return True + # A column that also holds query-less rows stores the numbers as floats. + return isinstance(query, (float, np.floating)) and float(query).is_integer() def query_column_label(engine: str, file_format: str) -> str: @@ -773,6 +792,30 @@ def query_column_sort_key(combo: tuple[str, str]) -> tuple[int, int, str, str]: ) +# Notes printed under the query table caption when a column of that variant is present. +FORMAT_VARIANT_NOTES = { + "scan-api": ( + "`[scan-api]` columns run DataFusion through the Scan API (`VortexTable`) on the V1 scan. " + "Compare them with their own develop times, not with the V2 `datafusion:vortex` column." + ), +} + + +def format_query_table_caption(df: pd.DataFrame, base_label: str, pr_label: str, threshold_pct: int) -> str: + """Say what the query table compares, and note any format variant its columns carry.""" + + lines = [ + f"Each cell is develop `{base_label}` โ†’ this PR `{pr_label}` (hot runs), with PR รท develop in " + f"parentheses: below 1.00 is faster. Changes past ยฑ{threshold_pct}% are bold. The geomean row " + "compares each target's geomean over its queries." + ] + variants = { + str(file_format).split(" [", 1)[1].rstrip("]") for file_format in df["file_format"] if " [" in str(file_format) + } + lines += [FORMAT_VARIANT_NOTES[variant] for variant in sorted(variants) if variant in FORMAT_VARIANT_NOTES] + return "
".join(lines) + + def format_query_table( df: pd.DataFrame, run: str, @@ -781,11 +824,13 @@ def format_query_table( ) -> str | None: """Render one row per query and one column per target, with a geomean row first. - Each cell is the PR's `run` ("hot" or "cold") time and its ratio to the base; the - geomean row holds the geomean time and the geomean ratio over the queries with a base. + Each cell compares the develop baseline's `run` ("hot" or "cold") time with the PR's and + gives their ratio. The geomean row does the same with each target's geomeans over its + queries; it does not compare targets with each other. """ value_column = f"{run}_value_pr" + base_column = f"{run}_value_base" ratio_column = "ratio" if run == "hot" else "cold_ratio" rows = df[df[value_column].notna()].copy() if rows.empty: @@ -801,14 +846,15 @@ def format_query_table( key=query_column_sort_key, ) - def cell(value: object, ratio: object) -> str: - return format_query_cell(value, ratio, improvement_threshold, regression_threshold) + def cell(base_value: object, value: object, ratio: object) -> str: + return format_query_cell(base_value, value, ratio, improvement_threshold, regression_threshold) geomean_cells = [] for engine, file_format in combos: target_rows = rows[(rows["engine"] == engine) & (rows["file_format"] == file_format)] geomean_cells.append( cell( + geometric_mean_from_values(target_rows[base_column]), geometric_mean_from_values(target_rows[value_column]), calculate_geometric_mean(target_rows, ratio_column), ) @@ -824,7 +870,7 @@ def cell(value: object, ratio: object) -> str: if match.empty: cells.append("โ€”") else: - cells.append(cell(match[value_column].iloc[0], match[ratio_column].iloc[0])) + cells.append(cell(match[base_column].iloc[0], match[value_column].iloc[0], match[ratio_column].iloc[0])) table_rows.append([label, *cells]) headers = ["query", *(query_column_label(engine, file_format) for engine, file_format in combos)] @@ -1160,10 +1206,11 @@ def format_report_help() -> str: "each run the warm path saves. Rows whose results predate per-run reporting " "show only one value, taken from the value the runner reported.", "- **Query tables**: One row per query and one column per target. Each cell " - "reads `PR time (PR/base)`, so `0.80` is 20% faster. A change that clears this " - "suite's threshold is bold and marked ๐Ÿ”ด slower or ๐ŸŸข faster; anything smaller is " - "noise here and is left plain. The `geomean` row holds the geomean time and the " - "geomean ratio. Hot runs are shown first and cold runs are folded below them.", + "reads `develop โ†’ PR (PR รท develop)`, so `(0.80)` is 20% faster than develop. A " + "change that clears this suite's threshold is bold and marked ๐Ÿ”ด slower or ๐ŸŸข " + "faster; anything smaller is noise here and is left plain. The `geomean` row " + "compares each target's geomean over its queries with develop's. Hot runs are " + "shown first and cold runs are folded below them.", "- **Other tables**: Each cell reads `PR / base / %diff`, marked the same way.", "", "", @@ -1338,6 +1385,8 @@ def main() -> None: sql_df = df3[sql_mask] hot_table = format_query_table(sql_df, "hot", improvement_threshold, regression_threshold) if hot_table is not None: + print(format_query_table_caption(sql_df, base_label, pr_commit_id[:8], threshold_pct)) + print("") print(hot_table) print("") cold_table = format_query_table(sql_df, "cold", improvement_threshold, regression_threshold) diff --git a/scripts/tests/test_benchmark_reporting.py b/scripts/tests/test_benchmark_reporting.py index 7f54d646f17..a33e7a81253 100644 --- a/scripts/tests/test_benchmark_reporting.py +++ b/scripts/tests/test_benchmark_reporting.py @@ -358,7 +358,7 @@ def test_comparison_report_retains_sql_analysis(tmp_path: Path) -> None: assert "How to read Verdict and Engines" in report # SQL queries share one table, with a row per query and a column per target. assert markdown_row(report, "query") == ["query", "datafusion:vortex", "datafusion:parquet"] - assert markdown_row(report, "tpch_q01") == ["tpch_q01", "**70.0 ns (0.88)** ๐ŸŸข", "105 ns (1.05)"] + assert markdown_row(report, "tpch_q01") == ["tpch_q01", "**80.0 โ†’ 70.0 ns (0.88)** ๐ŸŸข", "100 โ†’ 105 ns (1.05)"] assert "datafusion / " not in report assert "unknown" not in report @@ -407,11 +407,11 @@ def test_only_changes_past_the_suite_threshold_are_marked(tmp_path: Path) -> Non report = render_report(tmp_path, base_rows, pr_rows, "TPC-H") - assert markdown_row(report, "tpch_q01")[1] == "109 ns (1.09)" - assert markdown_row(report, "tpch_q02")[1] == "**111 ns (1.11)** ๐Ÿ”ด" - assert markdown_row(report, "tpch_q03")[1] == "**89.0 ns (0.89)** ๐ŸŸข" + assert markdown_row(report, "tpch_q01")[1] == "100 โ†’ 109 ns (1.09)" + assert markdown_row(report, "tpch_q02")[1] == "**100 โ†’ 111 ns (1.11)** ๐Ÿ”ด" + assert markdown_row(report, "tpch_q03")[1] == "**100 โ†’ 89.0 ns (0.89)** ๐ŸŸข" # The geomean row leads the table: geomean time and geomean ratio. - assert markdown_row(report, "**geomean**")[1] == "102 ns (1.02)" + assert markdown_row(report, "**geomean**")[1] == "100 โ†’ 102 ns (1.02)" def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: @@ -440,8 +440,8 @@ def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: # Hot runs come first; cold runs follow in their own folded table. hot, cold = markdown_rows(report, "tpch_q01") - assert hot == ["tpch_q01", "**50.0 ns (0.50)** ๐ŸŸข", "100 ns (1.00)"] - assert cold == ["tpch_q01", "**2.00 ยตs (2.00)** ๐Ÿ”ด", "1.00 ยตs (1.00)"] + assert hot == ["tpch_q01", "**100 โ†’ 50.0 ns (0.50)** ๐ŸŸข", "100 โ†’ 100 ns (1.00)"] + assert cold == ["tpch_q01", "**1.00 โ†’ 2.00 ยตs (2.00)** ๐Ÿ”ด", "1.00 โ†’ 1.00 ยตs (1.00)"] assert "Cold runs (first iteration)" in report assert "**Attributed Vortex impact**: -50.0%" in report assert "**Vortex (geomean)**: hot 0.500x โœ… ยท cold 2.000x โŒ" in report @@ -476,8 +476,8 @@ def test_verdict_ignores_a_cold_start_only_regression(tmp_path: Path) -> None: assert "**Attributed Vortex impact**: +0.0%" in report assert "**Vortex (geomean)**: hot 1.000x โž– ยท cold 4.000x โŒ" in report hot, cold = markdown_rows(report, "tpch_q01") - assert hot[1] == "100 ns (1.00)" - assert cold[1] == "**400 ns (4.00)** ๐Ÿ”ด" + assert hot[1] == "100 โ†’ 100 ns (1.00)" + assert cold[1] == "**100 โ†’ 400 ns (4.00)** ๐Ÿ”ด" def file_size_record(commit: str, size: int) -> dict[str, object]: @@ -800,7 +800,7 @@ def test_report_compares_ingest_records(tmp_path: Path) -> None: assert "**Engines**: DataFusion " in report assert "random-access " in report assert "ignored when records exist" not in report - assert markdown_row(report, "tpch_q01")[1:] == ["**70.0 ns (0.88)** ๐ŸŸข", "105 ns (1.05)"] + assert markdown_row(report, "tpch_q01")[1:] == ["**80.0 โ†’ 70.0 ns (0.88)** ๐ŸŸข", "100 โ†’ 105 ns (1.05)"] assert markdown_row(report, "random-access/taxi/uniform/parquet-cached")[1] == "105 / 100 / +5.0%" assert markdown_row(report, "random-access/taxi/uniform/lance-cached")[1] == "300 / โ€” / no baseline" assert "random-access / lance / ns " in report @@ -822,7 +822,7 @@ def test_report_compares_file_size_records_from_the_database(tmp_path: Path) -> report = render_report(tmp_path, base_records, pr_results, "TPC-H", pr_records) - assert markdown_row(report, "tpch_q01")[1] == "80.0 ns (1.00)" + assert markdown_row(report, "tpch_q01")[1] == "80.0 โ†’ 80.0 ns (1.00)" assert "File Size Changes (2 files changed, -16.7% overall, 1โ†‘ 1โ†“)" in report assert "| part-1.vortex | 10 | vortex-file-compressed | 50 B | 0 B | -50 B | -100.0% |" in report @@ -837,7 +837,7 @@ def test_report_handles_a_baseline_of_only_file_sizes(tmp_path: Path) -> None: report = render_report(tmp_path, base_records, pr_results, "TPC-H", pr_records) - assert markdown_row(report, "tpch_q01")[1] == "80.0 ns" + assert markdown_row(report, "tpch_q01")[1] == "โ€” โ†’ 80.0 ns" assert "File Size Changes (1 files changed, +25.0% overall, 1โ†‘ 0โ†“)" in report @@ -983,7 +983,9 @@ def test_query_table_puts_a_format_variant_beside_its_base_format(tmp_path: Path "datafusion:parquet", "duckdb:vortex", ] - assert markdown_row(report, "tpch_q01")[2] == "**1.20 ms (0.80)** ๐ŸŸข" + assert markdown_row(report, "tpch_q01")[2] == "**1.50 โ†’ 1.20 ms (0.80)** ๐ŸŸข" + # The variant's column carries a note on what it measures. + assert "`[scan-api]` columns run DataFusion through the Scan API" in report def test_format_duration_picks_a_readable_unit() -> None: @@ -995,3 +997,31 @@ def test_format_duration_picks_a_readable_unit() -> None: assert compare.format_duration(152_400_000) == "152 ms" assert compare.format_duration(2_500_000_000) == "2.50 s" assert compare.format_duration(float("nan")) == "โ€”" + + +def test_query_cell_names_both_units_when_they_differ() -> None: + compare = load_compare_module() + + assert compare.format_query_cell(980_000, 1_020_000, 1.04, 0.9, 1.1) == "980 ยตs โ†’ 1.02 ms (1.04)" + + +def test_query_table_says_what_it_compares(tmp_path: Path) -> None: + base = [query_record("base-sha", 1, "datafusion", "vortex-file-compressed", 80)] + pr = [query_record("pr-sha", 1, "datafusion", "vortex-file-compressed", 80)] + pr_results = [stored_timing_row("pr-sha", "ignored when records exist", 1)] + + report = render_report(tmp_path, base, pr_results, "TPC-H", pr) + + assert "Each cell is develop `base-sha` โ†’ this PR `pr-sha` (hot runs)" in report + assert "[scan-api]" not in report + + +def test_float_query_numbers_still_count_as_sql_queries() -> None: + compare = load_compare_module() + + assert compare.is_sql_query(3) + assert compare.is_sql_query(3.0) + assert not compare.is_sql_query(3.5) + assert not compare.is_sql_query("random-access/taxi/cached") + assert not compare.is_sql_query(None) + assert not compare.is_sql_query(True) From 4ea173db6b1b5925dc5d7414e1d43d136a66967f Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 20 Nov 2026 10:04:35 -0500 Subject: [PATCH 3/4] Fold the query tables under summaries The hot-run table now folds by default like the cold-run table, each under a summary of its size and how many cells cleared the threshold, with the headline summary above them. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Nicholas Gates --- scripts/compare-benchmark-jsons.py | 36 ++++++++++++++++------- scripts/tests/test_benchmark_reporting.py | 4 ++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/scripts/compare-benchmark-jsons.py b/scripts/compare-benchmark-jsons.py index 147b1a8fc54..6655335b9fa 100644 --- a/scripts/compare-benchmark-jsons.py +++ b/scripts/compare-benchmark-jsons.py @@ -816,6 +816,21 @@ def format_query_table_caption(df: pd.DataFrame, base_label: str, pr_label: str, return "
".join(lines) +def format_query_table_summary( + df: pd.DataFrame, run: str, title: str, improvement_threshold: float, regression_threshold: float +) -> str: + """Summarize a folded query table: its size and how many cells cleared the threshold each way.""" + + ratios = df["ratio" if run == "hot" else "cold_ratio"] + queries = df["name"].map(lambda name: str(name).rsplit("/", 1)[0]).nunique() + targets = df[["engine", "file_format"]].drop_duplicates().shape[0] + faster = int((ratios <= improvement_threshold).sum()) + slower = int((ratios >= regression_threshold).sum()) + query_noun = "query" if queries == 1 else "queries" + target_noun = "target" if targets == 1 else "targets" + return f"{title}: {queries} {query_noun} ร— {targets} {target_noun} ({faster}โ†‘ {slower}โ†“)" + + def format_query_table( df: pd.DataFrame, run: str, @@ -1383,20 +1398,21 @@ def main() -> None: sql_mask = df3["query"].map(is_sql_query) & df3["unit"].eq("ns") sql_df = df3[sql_mask] - hot_table = format_query_table(sql_df, "hot", improvement_threshold, regression_threshold) - if hot_table is not None: - print(format_query_table_caption(sql_df, base_label, pr_commit_id[:8], threshold_pct)) - print("") - print(hot_table) - print("") - cold_table = format_query_table(sql_df, "cold", improvement_threshold, regression_threshold) - if cold_table is not None: + caption = format_query_table_caption(sql_df, base_label, pr_commit_id[:8], threshold_pct) + for run, title in (("hot", "Hot runs"), ("cold", "Cold runs (first iteration)")): + table = format_query_table(sql_df, run, improvement_threshold, regression_threshold) + if table is None: + continue + summary = format_query_table_summary(sql_df, run, title, improvement_threshold, regression_threshold) print("
") - print("Cold runs (first iteration)") + print(f"{summary}") print("") print("
") print("") - print(cold_table) + if run == "hot": + print(caption) + print("") + print(table) print("") print("
") print("") diff --git a/scripts/tests/test_benchmark_reporting.py b/scripts/tests/test_benchmark_reporting.py index a33e7a81253..50ab995273b 100644 --- a/scripts/tests/test_benchmark_reporting.py +++ b/scripts/tests/test_benchmark_reporting.py @@ -442,7 +442,9 @@ def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: hot, cold = markdown_rows(report, "tpch_q01") assert hot == ["tpch_q01", "**100 โ†’ 50.0 ns (0.50)** ๐ŸŸข", "100 โ†’ 100 ns (1.00)"] assert cold == ["tpch_q01", "**1.00 โ†’ 2.00 ยตs (2.00)** ๐Ÿ”ด", "1.00 โ†’ 1.00 ยตs (1.00)"] - assert "Cold runs (first iteration)" in report + # Both tables fold by default, under a summary of what moved. + assert "Hot runs: 1 query ร— 2 targets (1โ†‘ 0โ†“)" in report + assert "Cold runs (first iteration): 1 query ร— 2 targets (0โ†‘ 1โ†“)" in report assert "**Attributed Vortex impact**: -50.0%" in report assert "**Vortex (geomean)**: hot 0.500x โœ… ยท cold 2.000x โŒ" in report assert "**Parquet (geomean)**: hot 1.000x โž– ยท cold 1.000x โž–" in report From 906d995fb43d2808a4bcae4fc67da111c6d9bb58 Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 20 Nov 2026 10:05:57 -0500 Subject: [PATCH 4/4] Show the geomean and a badge in query table summaries Co-Authored-By: Claude Opus 5.5 Signed-off-by: Nicholas Gates --- scripts/compare-benchmark-jsons.py | 8 ++++++-- scripts/tests/test_benchmark_reporting.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/compare-benchmark-jsons.py b/scripts/compare-benchmark-jsons.py index 6655335b9fa..ef2b4827e92 100644 --- a/scripts/compare-benchmark-jsons.py +++ b/scripts/compare-benchmark-jsons.py @@ -819,16 +819,20 @@ def format_query_table_caption(df: pd.DataFrame, base_label: str, pr_label: str, def format_query_table_summary( df: pd.DataFrame, run: str, title: str, improvement_threshold: float, regression_threshold: float ) -> str: - """Summarize a folded query table: its size and how many cells cleared the threshold each way.""" + """Summarize a folded query table: the geomean ratio over every cell with a develop time, + marked ๐ŸŸข or ๐Ÿ”ด past the threshold, then the table's size and how many cells moved each way.""" ratios = df["ratio" if run == "hot" else "cold_ratio"] + geomean = geometric_mean_from_values(ratios) + badge = format_change_marker(geomean, improvement_threshold, regression_threshold) or "โž–" + geomean_text = "no baseline" if pd.isna(geomean) else f"geomean {geomean:.3f}x {badge}" queries = df["name"].map(lambda name: str(name).rsplit("/", 1)[0]).nunique() targets = df[["engine", "file_format"]].drop_duplicates().shape[0] faster = int((ratios <= improvement_threshold).sum()) slower = int((ratios >= regression_threshold).sum()) query_noun = "query" if queries == 1 else "queries" target_noun = "target" if targets == 1 else "targets" - return f"{title}: {queries} {query_noun} ร— {targets} {target_noun} ({faster}โ†‘ {slower}โ†“)" + return f"{title}: {geomean_text} ยท {queries} {query_noun} ร— {targets} {target_noun} ({faster}โ†‘ {slower}โ†“)" def format_query_table( diff --git a/scripts/tests/test_benchmark_reporting.py b/scripts/tests/test_benchmark_reporting.py index 50ab995273b..0a44b46fa2c 100644 --- a/scripts/tests/test_benchmark_reporting.py +++ b/scripts/tests/test_benchmark_reporting.py @@ -443,8 +443,8 @@ def test_report_splits_cold_and_hot_runs(tmp_path: Path) -> None: assert hot == ["tpch_q01", "**100 โ†’ 50.0 ns (0.50)** ๐ŸŸข", "100 โ†’ 100 ns (1.00)"] assert cold == ["tpch_q01", "**1.00 โ†’ 2.00 ยตs (2.00)** ๐Ÿ”ด", "1.00 โ†’ 1.00 ยตs (1.00)"] # Both tables fold by default, under a summary of what moved. - assert "Hot runs: 1 query ร— 2 targets (1โ†‘ 0โ†“)" in report - assert "Cold runs (first iteration): 1 query ร— 2 targets (0โ†‘ 1โ†“)" in report + assert "Hot runs: geomean 0.707x ๐ŸŸข ยท 1 query ร— 2 targets (1โ†‘ 0โ†“)" in report + assert "Cold runs (first iteration): geomean 1.414x ๐Ÿ”ด ยท 1 query ร— 2 targets (0โ†‘ 1โ†“)" in report assert "**Attributed Vortex impact**: -50.0%" in report assert "**Vortex (geomean)**: hot 0.500x โœ… ยท cold 2.000x โŒ" in report assert "**Parquet (geomean)**: hot 1.000x โž– ยท cold 1.000x โž–" in report