Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/discovery.rs @ 43844:5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Rust's default hashing is slow, because it is meant for preventing collision
attacks.
For all of the current Rust code, we don't care about those attacks, because
if an person with bad intentions has write access to your repo, you have other
issues.
I've chosen to use the TwoXHash crate because it was made by a reputable member
of the Rust community and has very good benchmarks.
For now it does not seem to improve performance by much for the current code,
but it's something else to not worry about when benchmarking code: in a
previous experiment with copytracing in Rust, it accounted for more than 10%
of the time of the entire script.
Differential Revision: https://phab.mercurial-scm.org/D7116
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 14 Oct 2019 13:57:30 +0200 |
parents | ce6797ef6eab |
children | 2abffea40700 |
line wrap: on
line diff
--- a/rust/hg-core/src/discovery.rs Mon Dec 02 14:44:26 2019 +0100 +++ b/rust/hg-core/src/discovery.rs Mon Oct 14 13:57:30 2019 +0200 @@ -11,12 +11,11 @@ //! `mercurial.setdiscovery` use super::{Graph, GraphError, Revision, NULL_REVISION}; -use crate::ancestors::MissingAncestors; -use crate::dagops; +use crate::{ancestors::MissingAncestors, dagops, FastHashMap}; use rand::seq::SliceRandom; use rand::{thread_rng, RngCore, SeedableRng}; use std::cmp::{max, min}; -use std::collections::{HashMap, HashSet, VecDeque}; +use std::collections::{HashSet, VecDeque}; type Rng = rand_pcg::Pcg32; @@ -25,7 +24,7 @@ graph: G, // plays the role of self._repo common: MissingAncestors<G>, undecided: Option<HashSet<Revision>>, - children_cache: Option<HashMap<Revision, Vec<Revision>>>, + children_cache: Option<FastHashMap<Revision, Vec<Revision>>>, missing: HashSet<Revision>, rng: Rng, respect_size: bool, @@ -61,7 +60,7 @@ where I: Iterator<Item = Revision>, { - let mut distances: HashMap<Revision, u32> = HashMap::new(); + let mut distances: FastHashMap<Revision, u32> = FastHashMap::default(); let mut visit: VecDeque<Revision> = heads.into_iter().collect(); let mut factor: u32 = 1; let mut seen: HashSet<Revision> = HashSet::new(); @@ -328,7 +327,8 @@ } self.ensure_undecided()?; - let mut children: HashMap<Revision, Vec<Revision>> = HashMap::new(); + let mut children: FastHashMap<Revision, Vec<Revision>> = + FastHashMap::default(); for &rev in self.undecided.as_ref().unwrap() { for p in ParentsIterator::graph_parents(&self.graph, rev)? { children.entry(p).or_insert_with(|| Vec::new()).push(rev);