From cfdba897c989d2b8fec6c99be33e16c43ff7109b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sat, 19 Oct 2024 18:27:49 +0200 Subject: [PATCH] feat: add rustc-hash feature Changes in preparation of [rust-lang/rust#131936][1]: - Introduce `rustc-hash` dependency and feature. - Modify the `update.sh` script accordingly. [1]: https://github.com/rust-lang/rust/pull/131936 --- Cargo.toml | 10 ++++++++++ README.md | 12 ++++++++++++ update.sh | 4 +--- 3 files changed, 23 insertions(+), 3 deletions(-) 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..ba6a7fc 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,18 @@ 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). + +`cargo-semver-checks` benchmarked this change with `aws_sdk_ec2`'s JSON and +[observed a -3% improvement to the runtime][csc benchmarks]. The performance +here depends on how much time you spend querying the `HashMap`s, so as always, +measure first c: + +[csc benchmarks]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types/near/474855731 + ## 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