From 736086ae817e8fb8244bb204a44f4c4fdec232ef Mon Sep 17 00:00:00 2001 From: Fabian Murariu Date: Tue, 18 Jun 2024 12:27:01 +0100 Subject: [PATCH] increase sample size in graph_ops bench and fix earliest_time --- raphtory-benchmark/benches/graph_ops.rs | 8 +-- raphtory/src/db/api/storage/storage_ops.rs | 1 + raphtory/src/db/graph/views/deletion_graph.rs | 50 +++++++++++++++++-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/raphtory-benchmark/benches/graph_ops.rs b/raphtory-benchmark/benches/graph_ops.rs index 5ba5126a02..b2a89bb5e8 100644 --- a/raphtory-benchmark/benches/graph_ops.rs +++ b/raphtory-benchmark/benches/graph_ops.rs @@ -26,7 +26,7 @@ pub fn graph(c: &mut Criterion) { let group_name = "analysis_graph_window_100"; let make_graph = || graph.window(i64::MIN, i64::MAX); let mut graph_window_group_100 = c.benchmark_group(group_name); - graph_window_group_100.sample_size(10); + // graph_window_group_100.sample_size(10); run_analysis_benchmarks(&mut graph_window_group_100, make_graph, None); graph_window_group_100.finish(); @@ -38,7 +38,7 @@ pub fn graph(c: &mut Criterion) { let latest = graph.latest_time().expect("non-empty graph"); let earliest = graph.earliest_time().expect("non-empty graph"); let start = latest - (latest - earliest) / 10; - graph_window_group_10.sample_size(10); + // graph_window_group_10.sample_size(10); let make_graph = || graph.window(start, latest + 1); run_analysis_benchmarks(&mut graph_window_group_10, make_graph, None); graph_window_group_10.finish(); @@ -56,7 +56,7 @@ pub fn graph(c: &mut Criterion) { let subgraph = graph.subgraph(nodes); let group_name = "analysis_subgraph_10pc"; let mut subgraph_10 = c.benchmark_group(group_name); - subgraph_10.sample_size(10); + // subgraph_10.sample_size(10); let make_graph = || subgraph.clone(); run_analysis_benchmarks(&mut subgraph_10, make_graph, None); @@ -66,7 +66,7 @@ pub fn graph(c: &mut Criterion) { // subgraph windowed let group_name = "analysis_subgraph_10pc_windowed"; let mut subgraph_10_windowed = c.benchmark_group(group_name); - subgraph_10_windowed.sample_size(10); + // subgraph_10_windowed.sample_size(10); let make_graph = || subgraph.window(start, latest + 1); run_analysis_benchmarks(&mut subgraph_10_windowed, make_graph, None); diff --git a/raphtory/src/db/api/storage/storage_ops.rs b/raphtory/src/db/api/storage/storage_ops.rs index eb4bd714bd..203d7d11ca 100644 --- a/raphtory/src/db/api/storage/storage_ops.rs +++ b/raphtory/src/db/api/storage/storage_ops.rs @@ -86,6 +86,7 @@ impl GraphStorage { } } + #[inline(always)] pub fn node(&self, vid: VID) -> NodeStorageEntry { match self { GraphStorage::Mem(storage) => NodeStorageEntry::Mem(storage.nodes.get(vid)), diff --git a/raphtory/src/db/graph/views/deletion_graph.rs b/raphtory/src/db/graph/views/deletion_graph.rs index 1ec0815e86..7f43169dfe 100644 --- a/raphtory/src/db/graph/views/deletion_graph.rs +++ b/raphtory/src/db/graph/views/deletion_graph.rs @@ -240,11 +240,15 @@ impl TimeSemantics for PersistentGraph { } fn earliest_time_window(&self, start: i64, end: i64) -> Option { - self.0.earliest_time_window(start, end) + self.earliest_time_global() + .map(|t| t.max(start)) + .filter(|&t| t < end) } fn latest_time_window(&self, start: i64, end: i64) -> Option { - self.0.latest_time_window(start, end) + self.latest_time_global() + .map(|t| t.min(end.saturating_sub(1))) + .filter(|&t| t > start) } fn node_earliest_time_window(&self, v: VID, start: i64, end: i64) -> Option { @@ -685,7 +689,9 @@ mod test_deletions { db::{ api::view::time::internal::InternalTimeOps, graph::{ - edge::EdgeView, graph::assert_graph_equal, views::deletion_graph::PersistentGraph, + edge::EdgeView, + graph::assert_graph_equal, + views::deletion_graph::{PersistentGraph, TimeSemantics}, }, }, prelude::*, @@ -848,6 +854,44 @@ mod test_deletions { assert_graph_equal(&gm, &g.window(3, 5)) } + #[test] + fn test_materialize_window_earliest_time() { + let g = PersistentGraph::new(); + g.add_edge(0, 1, 2, NO_PROPS, None).unwrap(); + g.delete_edge(10, 1, 2, None).unwrap(); + + let ltg = g.latest_time_global(); + assert_eq!(ltg, Some(10)); + + let wg = g.window(3, 5); + + let e = wg.edge(1, 2).unwrap(); + assert_eq!(e.earliest_time(), Some(3)); + assert_eq!(e.latest_time(), Some(4)); + let n1 = wg.node(1).unwrap(); + assert_eq!(n1.earliest_time(), Some(3)); + assert_eq!(n1.latest_time(), Some(4)); + let n2 = wg.node(2).unwrap(); + assert_eq!(n2.earliest_time(), Some(3)); + assert_eq!(n2.latest_time(), Some(4)); + + let actual_lt = wg.latest_time(); + assert_eq!(actual_lt, Some(4)); + + let actual_et = wg.earliest_time(); + assert_eq!(actual_et, Some(3)); + + let gm = g + .window(3, 5) + .materialize() + .unwrap() + .into_persistent() + .unwrap(); + + let expected_et = gm.earliest_time(); + assert_eq!(actual_et, expected_et); + } + #[test] fn test_exploded_latest_time() { let g = PersistentGraph::new();