Skip to content

Commit

Permalink
feat: add feature to use rustc-hash (#423)
Browse files Browse the repository at this point in the history
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is
an implementation detail as AFAIK all types there are `pub(crate)` so we
never return an `FxHashMap` or `FxHashSet` on a public interface.

This bring a nice perf increase:

```console
❯ cargo criterion --bench indexed_crate
IndexedCrate/new(aws-sdk-ec2)
                        time:   [1.3474 s 1.3506 s 1.3537 s]
                        change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05)
                        Performance has regressed.

❯ cargo criterion --bench indexed_crate --features rustc-hash
IndexedCrate/new(aws-sdk-ec2)
                        time:   [1.1555 s 1.1561 s 1.1567 s]
                        change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05)
                        Performance has improved.

❯ cargo criterion --bench indexed_crate --features rayon
IndexedCrate/new(aws-sdk-ec2)
                        time:   [577.26 ms 578.45 ms 579.70 ms]
                        change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05)
                        Performance has improved.

❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash
IndexedCrate/new(aws-sdk-ec2)
                        time:   [486.94 ms 488.49 ms 490.13 ms]
                        change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05)
                        Performance has improved.
```

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
  • Loading branch information
jalil-salame and obi1kenobi authored Sep 1, 2024
1 parent 4d123be commit 00eb566
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ readme = "./README.md"
trustfall = "0.7.1"
rayon = { version = "1.10.0", optional = true }
rustdoc-types = "0.29.1"
rustc-hash = { version = "2.0.0", optional = true }

[features]
default = []
# Enable rayon for speeding up building `IndexedCrate`, this massively improves
# performance on big crates, but may impact performance on small crates and
# definitely increases the memory usage
rayon = ["dep:rayon"]
# Use rustc-hash::{FxHashMap, FxHashSet} internally for improved performance
rustc-hash = ["dep:rustc-hash"]

[[bench]]
name = "indexed_crate"
Expand Down
3 changes: 3 additions & 0 deletions src/visibility_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "rustc-hash")]
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
#[cfg(not(feature = "rustc-hash"))]
use std::collections::{HashMap, HashSet};

use rustdoc_types::{Crate, GenericArgs, Id, Item, ItemEnum, TypeAlias, Visibility};
Expand Down

0 comments on commit 00eb566

Please sign in to comment.