use fxhash

This commit is contained in:
nora 2023-07-02 15:42:17 +02:00
parent c50057a145
commit 076080f31d
3 changed files with 16 additions and 6 deletions

7
Cargo.lock generated
View file

@ -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"

View file

@ -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

View file

@ -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<String, Group>);
struct Groups(FxHashMap<String, Group>);
#[derive(Debug)]
struct Group {
@ -120,7 +119,7 @@ fn add_to_group(mut cur_groups: &mut Groups, components: Vec<String>, 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;
}