Skip to content

Commit

Permalink
Auto merge of #205 - Marwes:smaller_ir, r=Amanieu
Browse files Browse the repository at this point in the history
Reduce the amount of llvm IR instantiated

This works to improve the generated code in a similar way to #204 , however it is entirely orthogonal to it but also far more invasive.

The main change here is the introduction of `RawTableInner` which is contains all the fields that `RawTable` has but without being parameterized by `T`. Methods have been moved to this new type in parts or their entirety and `RawTable` forwards to these methods.

For this small test case with 4 different maps there is a reduction of the number of llvm lines generated by -17% (18088 / 21873 =0.82695560737) .

```rust
fn main() {
    let mut map1 = hashbrown::HashMap::new();
    map1.insert(1u8, "");
    map1.reserve(1000);
    let mut map2 = hashbrown::HashMap::new();
    map2.insert(1i16, "");
    map2.reserve(1000);
    let mut map3 = hashbrown::HashMap::new();
    map3.insert(3u16, "");
    map3.reserve(1000);
    let mut map4 = hashbrown::HashMap::new();
    map4.insert(3u64, "");
    map4.reserve(1000);
    dbg!((
        map1.iter().next(),
        map2.iter().next(),
        map3.iter().next(),
        map4.iter().next()
    ));
}

```

The commits are almost entirely orthogonal (except the first which does the main refactoring to support the rest) and if some are not desired they can be removed. If it helps, this PR could also be split up into multiple.

For most commitst I don't expect any performance degradation (unless LLVM stops inlining some function as it is now called more), but there are a couple of commits that does slow parts down however these should only be in the cold parts of the code (for instance, panic handling).
  • Loading branch information
bors committed Jan 26, 2021
2 parents 4c3ba70 + 99a7e3e commit d3297e4
Show file tree
Hide file tree
Showing 5 changed files with 689 additions and 507 deletions.
27 changes: 26 additions & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ macro_rules! bench_insert {
b.iter(|| {
m.clear();
for i in ($keydist).take(SIZE) {
m.insert(i, DropType(i));
m.insert(i, (DropType(i), [i; 20]));
}
black_box(&mut m);
});
Expand All @@ -105,6 +105,31 @@ bench_suite!(
insert_std_random
);

macro_rules! bench_grow_insert {
($name:ident, $maptype:ident, $keydist:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
b.iter(|| {
let mut m = $maptype::default();
for i in ($keydist).take(SIZE) {
m.insert(i, DropType(i));
}
black_box(&mut m);
})
}
};
}

bench_suite!(
bench_grow_insert,
grow_insert_ahash_serial,
grow_insert_std_serial,
grow_insert_ahash_highbits,
grow_insert_std_highbits,
grow_insert_ahash_random,
grow_insert_std_random
);

macro_rules! bench_insert_erase {
($name:ident, $maptype:ident, $keydist:expr) => {
#[bench]
Expand Down
2 changes: 1 addition & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ "${NO_STD}" = "1" ]; then
FEATURES="rustc-internal-api"
OP="build"
else
FEATURES="rustc-internal-api,serde,rayon"
FEATURES="rustc-internal-api,serde,rayon,raw"
OP="test"
fi
if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ pub mod raw {
pub use inner::*;

#[cfg(feature = "rayon")]
/// [rayon]-based parallel iterator types for hash maps.
/// You will rarely need to interact with it directly unless you have need
/// to name one of the iterator types.
///
/// [rayon]: https://docs.rs/rayon/1.0/rayon
pub mod rayon {
pub use crate::external_trait_impls::rayon::raw::*;
}
Expand Down
Loading

0 comments on commit d3297e4

Please sign in to comment.