Skip to content

Commit d3297e4

Browse files
committed
Auto merge of #205 - Marwes:smaller_ir, r=Amanieu
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).
2 parents 4c3ba70 + 99a7e3e commit d3297e4

File tree

5 files changed

+689
-507
lines changed

5 files changed

+689
-507
lines changed

benches/bench.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro_rules! bench_insert {
8686
b.iter(|| {
8787
m.clear();
8888
for i in ($keydist).take(SIZE) {
89-
m.insert(i, DropType(i));
89+
m.insert(i, (DropType(i), [i; 20]));
9090
}
9191
black_box(&mut m);
9292
});
@@ -105,6 +105,31 @@ bench_suite!(
105105
insert_std_random
106106
);
107107

108+
macro_rules! bench_grow_insert {
109+
($name:ident, $maptype:ident, $keydist:expr) => {
110+
#[bench]
111+
fn $name(b: &mut Bencher) {
112+
b.iter(|| {
113+
let mut m = $maptype::default();
114+
for i in ($keydist).take(SIZE) {
115+
m.insert(i, DropType(i));
116+
}
117+
black_box(&mut m);
118+
})
119+
}
120+
};
121+
}
122+
123+
bench_suite!(
124+
bench_grow_insert,
125+
grow_insert_ahash_serial,
126+
grow_insert_std_serial,
127+
grow_insert_ahash_highbits,
128+
grow_insert_std_highbits,
129+
grow_insert_ahash_random,
130+
grow_insert_std_random
131+
);
132+
108133
macro_rules! bench_insert_erase {
109134
($name:ident, $maptype:ident, $keydist:expr) => {
110135
#[bench]

ci/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ "${NO_STD}" = "1" ]; then
99
FEATURES="rustc-internal-api"
1010
OP="build"
1111
else
12-
FEATURES="rustc-internal-api,serde,rayon"
12+
FEATURES="rustc-internal-api,serde,rayon,raw"
1313
OP="test"
1414
fi
1515
if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ pub mod raw {
5757
pub use inner::*;
5858

5959
#[cfg(feature = "rayon")]
60+
/// [rayon]-based parallel iterator types for hash maps.
61+
/// You will rarely need to interact with it directly unless you have need
62+
/// to name one of the iterator types.
63+
///
64+
/// [rayon]: https://docs.rs/rayon/1.0/rayon
6065
pub mod rayon {
6166
pub use crate::external_trait_impls::rayon::raw::*;
6267
}

0 commit comments

Comments
 (0)