Skip to content

Commit 360ff0c

Browse files
committed
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]: rust-lang/rust#131936
1 parent c108e1c commit 360ff0c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ repository = "https://github.com/rust-lang/rustdoc-types"
99

1010
[dependencies]
1111
serde = {version="1", features=["derive"]}
12+
rustc-hash = {version="2", optional=true}
13+
14+
[features]
15+
default = []
16+
17+
# Switch the hashmaps used in rustdoc-types to the FxHashMap from rustc-hash.
18+
#
19+
# This might improve performace if your are reading the rustdoc JSON from large
20+
# crates like aws_sdk_ec2
21+
rustc-hash = ["dep:rustc-hash"]
1222

1323
[dev-dependencies]
1424
bincode = "1.3.3"

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ let krate: rustdoc_types::Crate = serde_json::from_str(&json_string)?;
1313
println!("the index has {} items", krate.index.len());
1414
```
1515

16+
For performance sensitive crates we suggest turning on the `rustc-hash`
17+
feature. This switches all data structures from `std::collections::HashMap` to
18+
`rustc-hash::FxHashMap` which improves performance when reading big JSON files
19+
(like `aws_sdk_rs`'s).
20+
21+
We have tested this on `cargo-semver-checks` using `aws_sdk_ec2`'s JSON and
22+
found a `~150ms` improvement per index (`c-s-c` builds two indexes from the
23+
JSON).
24+
1625
## Contributing
1726

1827
This repo is a reexport of

update.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ repo="rust"
99
branch="master"
1010

1111
curl -# https://raw.githubusercontent.com/${user}/${repo}/${branch}/src/rustdoc-json-types/lib.rs \
12-
| sed 's/rustc_hash::/std::collections::/g' \
13-
| sed 's/FxHashMap/HashMap/g' \
14-
| sed 's/^pub use /use /' \
12+
| sed '/^pub type FxHashMap.*$/d' \
1513
> src/lib.rs
1614

1715
curl -# https://raw.githubusercontent.com/${user}/${repo}/${branch}/src/rustdoc-json-types/tests.rs > src/tests.rs

0 commit comments

Comments
 (0)