Skip to content

Commit

Permalink
feat: add rustc-hash feature
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jalil-salame committed Oct 20, 2024
1 parent c108e1c commit 360ff0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 360ff0c

Please sign in to comment.