Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0d5b048

Browse files
committed
Move stuff around to better separate compile-time and runtime types and functions
1 parent 74a6505 commit 0d5b048

File tree

12 files changed

+217
-203
lines changed

12 files changed

+217
-203
lines changed

site/frontend/src/pages/compare/benchmarks/benchmarks.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="tsx">
22
import {computed, h} from "vue";
33
import TestCasesTable from "./test-cases-table.vue";
4-
import {CompileTestCase, TestCaseComparison} from "../data";
5-
import {CompareResponse, CompileBenchmarkFilter} from "../types";
4+
import {TestCaseComparison} from "../data";
5+
import {CompareResponse} from "../types";
6+
import {CompileBenchmarkFilter, CompileTestCase} from "../compile/common";
67
78
export interface BenchmarkProps {
89
data: CompareResponse;

site/frontend/src/pages/compare/benchmarks/test-cases-table.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="ts">
2-
import {CompileTestCase, TestCaseComparison} from "../data";
2+
import {TestCaseComparison} from "../data";
33
import Tooltip from "../tooltip.vue";
44
import {ArtifactDescription} from "../types";
55
import {percentClass} from "../shared";
6+
import {CompileTestCase} from "../compile/common";
67
78
const props = defineProps<{
89
id: string;

site/frontend/src/pages/compare/compile/common.ts

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
import {CompileBenchmarkFilter} from "../types";
1+
import {BenchmarkFilter, CompareResponse, StatComparison} from "../types";
2+
import {TestCaseComparison} from "../data";
23

3-
export const defaultFilter: CompileBenchmarkFilter = {
4+
export type CompileBenchmarkFilter = {
5+
profile: {
6+
check: boolean;
7+
debug: boolean;
8+
opt: boolean;
9+
doc: boolean;
10+
};
11+
scenario: {
12+
full: boolean;
13+
incrFull: boolean;
14+
incrUnchanged: boolean;
15+
incrPatched: boolean;
16+
};
17+
category: {
18+
primary: boolean;
19+
secondary: boolean;
20+
};
21+
} & BenchmarkFilter;
22+
export const defaultCompileFilter: CompileBenchmarkFilter = {
423
name: null,
524
nonRelevant: false,
625
showRawData: false,
@@ -21,3 +40,142 @@ export const defaultFilter: CompileBenchmarkFilter = {
2140
secondary: true,
2241
},
2342
};
43+
44+
export type Profile = "check" | "debug" | "opt" | "doc";
45+
export type Category = "primary" | "secondary";
46+
47+
export type CompileBenchmarkMap = Dict<{category: Category}>;
48+
49+
export interface CompileBenchmarkDescription {
50+
name: string;
51+
category: Category;
52+
}
53+
54+
export interface CompileBenchmarkComparison {
55+
benchmark: string;
56+
profile: Profile;
57+
scenario: string;
58+
comparison: StatComparison;
59+
}
60+
61+
export interface CompileTestCase {
62+
benchmark: string;
63+
profile: Profile;
64+
scenario: string;
65+
category: Category;
66+
}
67+
68+
export function computeCompileComparisonsWithNonRelevant(
69+
filter: CompileBenchmarkFilter,
70+
data: CompareResponse,
71+
benchmarkMap: CompileBenchmarkMap
72+
): TestCaseComparison<CompileTestCase>[] {
73+
function profileFilter(profile: Profile): boolean {
74+
if (profile === "check") {
75+
return filter.profile.check;
76+
} else if (profile === "debug") {
77+
return filter.profile.debug;
78+
} else if (profile === "opt") {
79+
return filter.profile.opt;
80+
} else if (profile === "doc") {
81+
return filter.profile.doc;
82+
} else {
83+
return true;
84+
}
85+
}
86+
87+
function scenarioFilter(scenario: string): boolean {
88+
if (scenario === "full") {
89+
return filter.scenario.full;
90+
} else if (scenario === "incr-full") {
91+
return filter.scenario.incrFull;
92+
} else if (scenario === "incr-unchanged") {
93+
return filter.scenario.incrUnchanged;
94+
} else if (scenario.startsWith("incr-patched")) {
95+
return filter.scenario.incrPatched;
96+
} else {
97+
// Unknown, but by default we should show things
98+
return true;
99+
}
100+
}
101+
102+
function categoryFilter(category: Category) {
103+
if (category === "primary" && !filter.category.primary) return false;
104+
if (category === "secondary" && !filter.category.secondary) return false;
105+
return true;
106+
}
107+
108+
function shouldShowTestCase(comparison: TestCaseComparison<CompileTestCase>) {
109+
const name = `${comparison.testCase.benchmark} ${comparison.testCase.profile} ${comparison.testCase.scenario}`;
110+
const nameFilter = filter.name && filter.name.trim();
111+
const nameFiltered = !nameFilter || name.includes(nameFilter);
112+
113+
return (
114+
profileFilter(comparison.testCase.profile) &&
115+
scenarioFilter(comparison.testCase.scenario) &&
116+
categoryFilter(comparison.testCase.category) &&
117+
nameFiltered
118+
);
119+
}
120+
121+
let testCases = data.compile_comparisons
122+
.map(
123+
(c: CompileBenchmarkComparison): TestCaseComparison<CompileTestCase> => {
124+
const datumA = c.comparison.statistics[0];
125+
const datumB = c.comparison.statistics[1];
126+
127+
// In the vast majority of cases, we can do the proportional change calculation. However, some
128+
// metrics can be zero. If the initial value is 0, we can't compute the new value as a
129+
// percentage change of the old one. If both values are 0, we can say the change is also 0%.
130+
// If the new value is not 0, the percentage is not really meaningful, but we can say it's 100%.
131+
let percent;
132+
if (datumA === 0) {
133+
if (datumB === 0) {
134+
percent = 0;
135+
} else {
136+
percent = 100;
137+
}
138+
} else {
139+
percent = 100 * ((datumB - datumA) / datumA);
140+
}
141+
142+
return {
143+
testCase: {
144+
benchmark: c.benchmark,
145+
profile: c.profile,
146+
scenario: c.scenario,
147+
category: (benchmarkMap[c.benchmark] || {}).category || "secondary",
148+
},
149+
isRelevant: c.comparison.is_relevant,
150+
significanceFactor: c.comparison.significance_factor,
151+
significanceThreshold: c.comparison.significance_threshold * 100.0, // ensure the threshold is in %
152+
datumA,
153+
datumB,
154+
percent,
155+
};
156+
}
157+
)
158+
.filter((tc) => shouldShowTestCase(tc));
159+
160+
// Sort by name first, so that there is a canonical ordering
161+
// of test cases. This ensures the overall order is stable, even if
162+
// individual benchmarks have the same largestChange value.
163+
testCases.sort((a, b) =>
164+
a.testCase.benchmark.localeCompare(b.testCase.benchmark)
165+
);
166+
testCases.sort((a, b) => Math.abs(b.percent) - Math.abs(a.percent));
167+
168+
return testCases;
169+
}
170+
171+
export function createCompileBenchmarkMap(
172+
data: CompareResponse
173+
): CompileBenchmarkMap {
174+
const benchmarks = {};
175+
for (const benchmark of data.compile_benchmark_data) {
176+
benchmarks[benchmark.name] = {
177+
category: benchmark.category,
178+
};
179+
}
180+
return benchmarks;
181+
}

site/frontend/src/pages/compare/compile/export.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {CompileTestCase, computeSummary, TestCaseComparison} from "../data";
1+
import {computeSummary, TestCaseComparison} from "../data";
2+
import {CompileTestCase} from "./common";
23

34
export function exportToMarkdown(
45
comparisons: TestCaseComparison<CompileTestCase>[]

site/frontend/src/pages/compare/compile/filters.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
22
import Toggle from "../toggle.vue";
3-
import {CompileBenchmarkFilter} from "../types";
43
import Tooltip from "../tooltip.vue";
54
import {ref, toRaw, watch} from "vue";
65
import {deepCopy} from "../../../utils/copy";
76
import {PREF_FILTERS_OPENED} from "../prefs";
87
import {createPersistedRef} from "../../../storage";
8+
import {CompileBenchmarkFilter} from "./common";
99
1010
const props = defineProps<{
1111
// When reset, set filter to this value

site/frontend/src/pages/compare/compile/page.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ import Filters from "./filters.vue";
44
import OverallTable from "../summary/overall-table.vue";
55
import Aggregations from "../summary/aggregations.vue";
66
import Benchmarks from "../benchmarks/benchmarks.vue";
7-
import {
8-
CompareResponse,
9-
CompareSelector,
10-
CompileBenchmarkFilter,
11-
} from "../types";
7+
import {CompareResponse, CompareSelector} from "../types";
128
import {computed, ref} from "vue";
139
import {changeUrl, getUrlParams} from "../../../utils/navigation";
1410
import {exportToMarkdown} from "./export";
11+
import {computeSummary, filterNonRelevant} from "../data";
1512
import {
13+
CompileBenchmarkFilter,
14+
computeCompileComparisonsWithNonRelevant,
1615
createCompileBenchmarkMap,
17-
computeSummary,
18-
computeTestCasesWithNonRelevant,
19-
filterNonRelevant,
20-
} from "../data";
21-
import {defaultFilter} from "./common";
16+
defaultCompileFilter,
17+
} from "./common";
2218
2319
const props = defineProps<{
2420
data: CompareResponse;
@@ -139,7 +135,7 @@ function refreshQuickLinks() {
139135
}
140136
141137
function updateFilter(newFilter: CompileBenchmarkFilter) {
142-
storeFilterToUrl(newFilter, defaultFilter, getUrlParams());
138+
storeFilterToUrl(newFilter, defaultCompileFilter, getUrlParams());
143139
filter.value = newFilter;
144140
refreshQuickLinks();
145141
}
@@ -151,11 +147,15 @@ function exportData() {
151147
const urlParams = getUrlParams();
152148
153149
const quickLinksKey = ref(0);
154-
const filter = ref(loadFilterFromUrl(urlParams, defaultFilter));
150+
const filter = ref(loadFilterFromUrl(urlParams, defaultCompileFilter));
155151
156152
const benchmarkMap = createCompileBenchmarkMap(props.data);
157153
const allTestCases = computed(() =>
158-
computeTestCasesWithNonRelevant(filter.value, props.data, benchmarkMap)
154+
computeCompileComparisonsWithNonRelevant(
155+
filter.value,
156+
props.data,
157+
benchmarkMap
158+
)
159159
);
160160
const testCases = computed(() =>
161161
filterNonRelevant(filter.value, allTestCases.value)
@@ -166,7 +166,7 @@ const filteredSummary = computed(() => computeSummary(testCases.value));
166166
<template>
167167
<QuickLinks :stat="selector.stat" :key="quickLinksKey" />
168168
<Filters
169-
:defaultFilter="defaultFilter"
169+
:defaultFilter="defaultCompileFilter"
170170
:initialFilter="filter"
171171
@change="updateFilter"
172172
@export="exportData"

0 commit comments

Comments
 (0)