diff options
author | Aria Shrimpton <me@aria.rip> | 2024-03-19 21:32:59 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-03-19 21:32:59 +0000 |
commit | 9df3499dc60ec51287659df1d2d152d38595b3ef (patch) | |
tree | 4bf5bdb5cc0fea502cd2c38bff8fa5cae5ef499a /src/crates | |
parent | 3003370551c03744691d2915c635b528292ba86b (diff) |
improvements to nsplit
Diffstat (limited to 'src/crates')
-rw-r--r-- | src/crates/candelabra/src/profiler/info.rs | 50 |
1 files changed, 16 insertions, 34 deletions
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::<f64>() - - after_costs[split_idx..].iter().sum::<f64>(); - - 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::<f64>() + 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::<f64>() + switching_cost, + )) } /// Estimate the cost of using the implementation with the given cost model |