From 076080f31d69f12d952466c4b5f1d2d3e50fabb8 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 2 Jul 2023 15:42:17 +0200 Subject: [PATCH] use fxhash --- Cargo.lock | 7 +++++++ Cargo.toml | 4 ++++ src/main.rs | 11 +++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d9aa18..275e54a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,7 @@ dependencies = [ "eyre", "object", "rustc-demangle", + "rustc-hash", "serde", "serde_json", ] @@ -128,6 +129,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "ruzstd" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index c7f3483..5b32a48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,9 @@ edition = "2021" eyre = "0.6.8" object = "0.31.1" rustc-demangle = { version = "0.1.23", features = ["std"] } +rustc-hash = "1.1.0" serde = { version = "1.0.164", features = ["derive"] } serde_json = "1.0.99" + +[profile.release] +debug = 1 diff --git a/src/main.rs b/src/main.rs index 6387560..7d4c5e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ -use std::collections::HashMap; - use eyre::{eyre, Context, ContextCompat, Result}; use object::{Object, ObjectSection, ObjectSymbol}; use serde::Serialize; +use rustc_hash::FxHashMap; #[derive(serde::Serialize)] struct SerGroup { @@ -17,7 +16,7 @@ fn main() -> Result<()> { .nth(1) .unwrap_or("./target/debug/my-binary-is-thicc-af".into()); - let limit = 10; + let limit = 100; let data = std::fs::read(&path).wrap_err_with(|| format!("error opening `{path}`"))?; let object = object::File::parse(data.as_slice()).context("could not parse object file")?; @@ -53,7 +52,7 @@ fn main() -> Result<()> { symbol_sizes.sort_by_key(|&(_, size)| size); symbol_sizes.reverse(); - let mut root_groups = Groups(HashMap::new()); + let mut root_groups = Groups(FxHashMap::default()); for (sym, size) in symbol_sizes { let mut components = symbol_components(sym).with_context(|| sym.to_string())?; @@ -78,7 +77,7 @@ fn main() -> Result<()> { } #[derive(Debug)] -struct Groups(HashMap); +struct Groups(FxHashMap); #[derive(Debug)] struct Group { @@ -120,7 +119,7 @@ fn add_to_group(mut cur_groups: &mut Groups, components: Vec, sym_size: for head in components { let grp = cur_groups.0.entry(head).or_insert(Group { weight: sym_size, // NOTE: This is a dummy value for everything but the innermost nesting. - children: Groups(HashMap::new()), + children: Groups(FxHashMap::default()), }); cur_groups = &mut grp.children; }