Skip to content

Commit 96d14fe

Browse files
committed
fix: normalize sizes for same-name deps
1 parent 5df0067 commit 96d14fe

File tree

3 files changed

+55
-42
lines changed

3 files changed

+55
-42
lines changed

examples/pugio.svg

Lines changed: 38 additions & 38 deletions
Loading

src/graph.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,22 @@ impl NodeWeight {
3434
}
3535
}
3636

37+
pub fn normalize_sizes(graph: &StableGraph<NodeWeight, ()>, map: &mut HashMap<String, usize>) {
38+
let mut counts = HashMap::with_capacity(graph.node_count());
39+
for node in graph.node_weights() {
40+
*counts.entry(node.short()).or_default() += 1;
41+
}
42+
43+
for (name, size) in map.iter_mut() {
44+
let count = counts.get(name.as_str()).copied().unwrap_or(1);
45+
*size /= count;
46+
}
47+
}
48+
3749
pub fn cum_sums(
3850
graph: &StableGraph<NodeWeight, ()>,
3951
map: &HashMap<String, usize>,
4052
) -> (Vec<usize>, f32) {
41-
// TODO: currently the same size is used for all nodes with the same name, change?
4253
let mut cum_sums = vec![0; graph.capacity().0];
4354

4455
for (idx, size) in graph.node_indices().filter_map(|i| {

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
config::Config,
1010
dot::{output_dot, output_svg},
1111
graph::{
12-
NodeWeight, change_root, cum_sums, dep_counts, remove_deep_deps, remove_excluded_deps,
13-
remove_small_deps, rev_dep_counts,
12+
NodeWeight, change_root, cum_sums, dep_counts, normalize_sizes, remove_deep_deps,
13+
remove_excluded_deps, remove_small_deps, rev_dep_counts,
1414
},
1515
template::get_templates,
1616
};
@@ -127,7 +127,9 @@ fn main() -> anyhow::Result<()> {
127127
let mut graph = get_dep_graph(&tree_output).context("failed to parse cargo-tree output")?;
128128

129129
let bloat_output = cargo_bloat_output(&options)?;
130-
let size_map = get_size_map(&bloat_output).context("failed to parse cargo-bloat output")?;
130+
let mut size_map = get_size_map(&bloat_output).context("failed to parse cargo-bloat output")?;
131+
132+
normalize_sizes(&graph, &mut size_map);
131133

132134
let mut root_idx = petgraph::graph::NodeIndex::new(0);
133135

0 commit comments

Comments
 (0)