Skip to content

Commit 5605158

Browse files
committed
Remove creation of now unnecessary graph data used by old graph endpoint
1 parent 3c04508 commit 5605158

File tree

2 files changed

+13
-89
lines changed

2 files changed

+13
-89
lines changed

site/src/api.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,6 @@ pub mod graph {
6565
PercentRelative,
6666
}
6767

68-
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
69-
pub struct GraphData {
70-
pub commit: u16,
71-
pub absolute: f32,
72-
// Percent change from the first datapoint shown
73-
pub percent_first: f32,
74-
pub y: f32,
75-
pub x: u64,
76-
pub is_interpolated: bool,
77-
}
78-
79-
#[derive(Debug, PartialEq, Clone, Serialize)]
80-
pub struct Response {
81-
pub benchmarks: HashMap<String, HashMap<String, Vec<(String, Vec<GraphData>)>>>,
82-
pub max: HashMap<String, f32>,
83-
pub colors: Vec<String>,
84-
pub commits: Vec<String>,
85-
}
86-
8768
#[derive(Debug, PartialEq, Clone, Serialize)]
8869
pub struct Series {
8970
// y-values

site/src/request_handlers/graph.rs

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use collector::Bound;
2-
use std::cell::RefCell;
32
use std::collections::HashMap;
4-
use std::convert::TryInto;
5-
use std::str;
63
use std::sync::Arc;
74

85
use crate::api::graph::GraphKind;
@@ -38,9 +35,9 @@ pub async fn handle_graph(
3835

3936
let mut benchmarks = HashMap::new();
4037

41-
let raw = handle_graph_impl(body, ctxt).await?;
38+
let benchmarks_impl = handle_graph_impl(body, ctxt).await?;
4239

43-
for (benchmark_, benchmark_data) in raw.benchmarks.iter() {
40+
for (benchmark_, benchmark_data) in benchmarks_impl.iter() {
4441
let mut by_profile = HashMap::with_capacity(3);
4542

4643
for (profile, series) in benchmark_data.iter() {
@@ -86,13 +83,15 @@ pub async fn handle_graph(
8683
Ok(resp)
8784
}
8885

89-
static INTERPOLATED_COLOR: &str = "#fcb0f1";
86+
struct GraphData {
87+
y: f32,
88+
is_interpolated: bool,
89+
}
9090

9191
async fn handle_graph_impl(
9292
body: graph::Request,
9393
ctxt: &SiteCtxt,
94-
) -> ServerResult<graph::Response> {
95-
let cc = CommitIdxCache::new();
94+
) -> ServerResult<HashMap<String, HashMap<String, Vec<(String, Vec<GraphData>)>>>> {
9695
let range = ctxt.data_range(body.start.clone()..=body.end.clone());
9796
let commits: Arc<Vec<_>> = Arc::new(range.iter().map(|c| c.clone().into()).collect());
9897

@@ -113,7 +112,7 @@ async fn handle_graph_impl(
113112
.into_iter()
114113
.map(|sr| {
115114
sr.interpolate()
116-
.map(|series| to_graph_data(&cc, body.kind, series).collect::<Vec<_>>())
115+
.map(|series| to_graph_data(body.kind, series).collect::<Vec<_>>())
117116
})
118117
.collect::<Vec<_>>();
119118

@@ -183,7 +182,7 @@ async fn handle_graph_impl(
183182
.collect(),
184183
)
185184
.map(|((c, d), i)| ((c, Some(d.expect("interpolated") / against)), i));
186-
let graph_data = to_graph_data(&cc, body.kind, averaged).collect::<Vec<_>>();
185+
let graph_data = to_graph_data(body.kind, averaged).collect::<Vec<_>>();
187186
series.push(selector::SeriesResponse {
188187
path: selector::Path::new()
189188
.set(PathComponent::Benchmark("Summary".into()))
@@ -203,17 +202,8 @@ async fn handle_graph_impl(
203202
}
204203

205204
let mut by_test_case = HashMap::new();
206-
let mut by_benchmark_max = HashMap::new();
207205
for sr in series {
208206
let benchmark = sr.path.get::<Benchmark>()?.to_string();
209-
let max = by_benchmark_max
210-
.entry(benchmark.clone())
211-
.or_insert(f32::MIN);
212-
*max = sr
213-
.series
214-
.iter()
215-
.map(|p| p.y)
216-
.fold(*max, |max, p| max.max(p));
217207
by_test_case
218208
.entry(benchmark)
219209
.or_insert_with(HashMap::new)
@@ -222,76 +212,29 @@ async fn handle_graph_impl(
222212
.push((sr.path.get::<Scenario>()?.to_string(), sr.series));
223213
}
224214

225-
Ok(graph::Response {
226-
max: by_benchmark_max,
227-
benchmarks: by_test_case,
228-
colors: vec![String::new(), String::from(INTERPOLATED_COLOR)],
229-
commits: cc.into_commits(),
230-
})
231-
}
232-
233-
struct CommitIdxCache {
234-
commit_idx: RefCell<HashMap<String, u16>>,
235-
commits: RefCell<Vec<String>>,
236-
}
237-
238-
impl CommitIdxCache {
239-
fn new() -> Self {
240-
Self {
241-
commit_idx: RefCell::new(HashMap::new()),
242-
commits: RefCell::new(Vec::new()),
243-
}
244-
}
245-
246-
fn into_commits(self) -> Vec<String> {
247-
std::mem::take(&mut *self.commits.borrow_mut())
248-
}
249-
250-
fn lookup(&self, commit: String) -> u16 {
251-
*self
252-
.commit_idx
253-
.borrow_mut()
254-
.entry(commit.clone())
255-
.or_insert_with(|| {
256-
let idx = self.commits.borrow().len();
257-
self.commits.borrow_mut().push(commit);
258-
idx.try_into().unwrap_or_else(|_| {
259-
panic!("{} too big", idx);
260-
})
261-
})
262-
}
215+
Ok(by_test_case)
263216
}
264217

265218
fn to_graph_data<'a>(
266-
cc: &'a CommitIdxCache,
267219
kind: GraphKind,
268220
points: impl Iterator<Item = ((ArtifactId, Option<f64>), Interpolated)> + 'a,
269-
) -> impl Iterator<Item = graph::GraphData> + 'a {
221+
) -> impl Iterator<Item = GraphData> + 'a {
270222
let mut first = None;
271223
let mut prev = None;
272-
points.map(move |((aid, point), interpolated)| {
273-
let commit = if let ArtifactId::Commit(commit) = aid {
274-
commit
275-
} else {
276-
unimplemented!()
277-
};
224+
points.map(move |((_aid, point), interpolated)| {
278225
let point = point.expect("interpolated");
279226
first = Some(first.unwrap_or(point));
280227
let first = first.unwrap();
281228
let percent_first = (point - first) / first * 100.0;
282229
let previous_point = prev.unwrap_or(point);
283230
let percent_prev = (point - previous_point) / previous_point * 100.0;
284231
prev = Some(point);
285-
graph::GraphData {
286-
commit: cc.lookup(commit.sha),
287-
absolute: point as f32,
288-
percent_first: percent_first as f32,
232+
GraphData {
289233
y: match kind {
290234
GraphKind::Raw => point as f32,
291235
GraphKind::PercentRelative => percent_prev as f32,
292236
GraphKind::PercentFromFirst => percent_first as f32,
293237
},
294-
x: commit.date.0.timestamp() as u64 * 1000, // all dates are since 1970
295238
is_interpolated: interpolated.is_interpolated(),
296239
}
297240
})

0 commit comments

Comments
 (0)