Skip to content

Commit 68210a1

Browse files
committed
Revert "std: Cache HashMap keys in TLS"
This reverts commit eaeef3d. This is a short-term workaround to rust-lang#36481.
1 parent 22d15ea commit 68210a1

File tree

1 file changed

+2
-27
lines changed
  • src/libstd/collections/hash

1 file changed

+2
-27
lines changed

src/libstd/collections/hash/map.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1963,33 +1963,8 @@ impl RandomState {
19631963
#[allow(deprecated)] // rand
19641964
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
19651965
pub fn new() -> RandomState {
1966-
// Historically this function did not cache keys from the OS and instead
1967-
// simply always called `rand::thread_rng().gen()` twice. In #31356 it
1968-
// was discovered, however, that because we re-seed the thread-local RNG
1969-
// from the OS periodically that this can cause excessive slowdown when
1970-
// many hash maps are created on a thread. To solve this performance
1971-
// trap we cache the first set of randomly generated keys per-thread.
1972-
//
1973-
// In doing this, however, we lose the property that all hash maps have
1974-
// nondeterministic iteration order as all of those created on the same
1975-
// thread would have the same hash keys. This property has been nice in
1976-
// the past as it allows for maximal flexibility in the implementation
1977-
// of `HashMap` itself.
1978-
//
1979-
// The constraint here (if there even is one) is just that maps created
1980-
// on the same thread have the same iteration order, and that *may* be
1981-
// relied upon even though it is not a documented guarantee at all of
1982-
// the `HashMap` type. In any case we've decided that this is reasonable
1983-
// for now, so caching keys thread-locally seems fine.
1984-
thread_local!(static KEYS: (u64, u64) = {
1985-
let r = rand::OsRng::new();
1986-
let mut r = r.expect("failed to create an OS RNG");
1987-
(r.gen(), r.gen())
1988-
});
1989-
1990-
KEYS.with(|&(k0, k1)| {
1991-
RandomState { k0: k0, k1: k1 }
1992-
})
1966+
let mut r = rand::thread_rng();
1967+
RandomState { k0: r.gen(), k1: r.gen() }
19931968
}
19941969
}
19951970

0 commit comments

Comments
 (0)