Skip to content

Commit a4b19c4

Browse files
committed
Add cache for downloading graphs on compare page
1 parent 57dc663 commit a4b19c4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

site/frontend/src/graph/resolver.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {GraphData, GraphsSelector} from "./data";
2+
import {loadGraphs} from "./api";
3+
4+
export class GraphResolver {
5+
private cache: Dict<GraphData> = {};
6+
7+
public async loadGraph(selector: GraphsSelector): Promise<GraphData> {
8+
const key = `${selector.benchmark};${selector.profile};${selector.scenario};${selector.start};${selector.end};${selector.stat};${selector.kind}`;
9+
if (!this.cache.hasOwnProperty(key)) {
10+
this.cache[key] = await loadGraphs(selector);
11+
}
12+
13+
return this.cache[key];
14+
}
15+
}
16+
17+
/**
18+
* This is essentially a global variable, but it makes the code simpler and
19+
* since we currently don't have any unit tests, we don't really need to avoid
20+
* global variables that much. If needed, it could be provided to Vue components
21+
* from a parent via props or context.
22+
*/
23+
export const GRAPH_RESOLVER = new GraphResolver();

site/frontend/src/pages/compare/compile/table/benchmark-detail.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {
77
} from "../common";
88
import {computed, onMounted, Ref, ref} from "vue";
99
import Tooltip from "../../tooltip.vue";
10-
import {loadGraphs} from "../../../../graph/api";
1110
import {ArtifactDescription} from "../../types";
1211
import {getDateInPast} from "./utils";
1312
import {renderPlots} from "../../../../graph/render";
13+
import {GRAPH_RESOLVER} from "../../../../graph/resolver";
14+
import {GraphKind} from "../../../../graph/data";
1415
1516
const props = defineProps<{
1617
testCase: CompileTestCase;
@@ -27,9 +28,9 @@ async function renderGraph() {
2728
stat: props.metric,
2829
start: getDateInPast(props.artifact),
2930
end: props.artifact.commit,
30-
kind: "raw",
31+
kind: "raw" as GraphKind,
3132
};
32-
const graphData = await loadGraphs(selector);
33+
const graphData = await GRAPH_RESOLVER.loadGraph(selector);
3334
renderPlots(graphData, selector, chartElement.value, {
3435
renderTitle: false,
3536
});

0 commit comments

Comments
 (0)