diff --git a/Cargo.toml b/Cargo.toml index bfbee52..54a03ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,16 @@ repository = "https://github.com/rust-lang/rustdoc-types" [dependencies] serde = {version="1", features=["derive"]} +rustc-hash = {version="2", optional=true} + +[features] +default = [] + +# Switch the hashmaps used in rustdoc-types to the FxHashMap from rustc-hash. +# +# This might improve performace if your are reading the rustdoc JSON from large +# crates like aws_sdk_ec2 +rustc-hash = ["dep:rustc-hash"] [dev-dependencies] bincode = "1.3.3" diff --git a/README.md b/README.md index 3578e35..6251b8e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,15 @@ let krate: rustdoc_types::Crate = serde_json::from_str(&json_string)?; println!("the index has {} items", krate.index.len()); ``` +For performance sensitive crates we suggest turning on the `rustc-hash` +feature. This switches all data structures from `std::collections::HashMap` to +`rustc-hash::FxHashMap` which improves performance when reading big JSON files +(like `aws_sdk_rs`'s). + +We have tested this on `cargo-semver-checks` using `aws_sdk_ec2`'s JSON and +found a `~150ms` improvement per index (`c-s-c` builds two indexes from the +JSON). + ## Contributing This repo is a reexport of diff --git a/update.sh b/update.sh index 6d10f2c..65612f4 100755 --- a/update.sh +++ b/update.sh @@ -9,9 +9,7 @@ repo="rust" branch="master" curl -# https://raw.githubusercontent.com/${user}/${repo}/${branch}/src/rustdoc-json-types/lib.rs \ - | sed 's/rustc_hash::/std::collections::/g' \ - | sed 's/FxHashMap/HashMap/g' \ - | sed 's/^pub use /use /' \ + | sed '/^pub type FxHashMap.*$/d' \ > src/lib.rs curl -# https://raw.githubusercontent.com/${user}/${repo}/${branch}/src/rustdoc-json-types/tests.rs > src/tests.rs