From 9df3499dc60ec51287659df1d2d152d38595b3ef Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Tue, 19 Mar 2024 21:32:59 +0000 Subject: improvements to nsplit --- src/crates/candelabra/src/profiler/info.rs | 50 ++++++++++-------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/crates/candelabra/src/profiler/info.rs b/src/crates/candelabra/src/profiler/info.rs index 30e7df7..fe66c3c 100644 --- a/src/crates/candelabra/src/profiler/info.rs +++ b/src/crates/candelabra/src/profiler/info.rs @@ -105,48 +105,30 @@ impl UsageProfile { return None; } - // calculate cost of switching let before = &top_by_partition[0].0; let after = &top_by_partition[split_idx].0; - // halfway between the two partitions + // figure out when to switch let copy_n = { let before = self.0[split_idx - 1].avg_n; let after = self.0[split_idx].avg_n; - (before + after) / 2.0 + ((before + after) / 2.0).min(before + (before / 2.0)) }; - let after_model = candidates.get(after).unwrap(); - let switching_cost = copy_n * after_model.by_op.get("insert")?.estimatef(copy_n); - // see if it's "worth it" - let before_costs = &costs_by_partitions - .iter() - .find(|(name, _)| **name == before) - .unwrap() - .1; - let after_costs = &costs_by_partitions - .iter() - .find(|(name, _)| **name == after) - .unwrap() - .1; - let not_switching_cost = before_costs[split_idx..].iter().sum::() - - after_costs[split_idx..].iter().sum::(); - - debug!("Estimated switching cost: {}", switching_cost); - debug!("Estimated not switching cost: {}", not_switching_cost); - - if not_switching_cost < switching_cost { - None - } else { - Some(( - ContainerSelection::Split { - before: before.to_string(), - threshold: copy_n as usize, - after: after.to_string(), - }, - top_by_partition.iter().map(|(_, v)| v).sum::() + switching_cost, - )) - } + // calculate cost of switching + let before_model = candidates.get(before).unwrap(); + let after_model = candidates.get(after).unwrap(); + let switching_cost = (copy_n * after_model.by_op.get("insert")?.estimatef(copy_n)) + + before_model.by_op.get("clear")?.estimatef(copy_n); + + Some(( + ContainerSelection::Split { + before: before.to_string(), + threshold: copy_n as usize, + after: after.to_string(), + }, + top_by_partition.iter().map(|(_, v)| v).sum::() + switching_cost, + )) } /// Estimate the cost of using the implementation with the given cost model -- cgit v1.2.3