comparison rust/hg-core/src/dagops.rs @ 41717:9060af281be7

rust: itering less on MissingAncestors.bases for max() Instead of iterating on the whole `self.bases` each time to find its max, we keep the latter in a separate member attribute and keep it up to date in `add_bases()` On a perfdiscovery done on PyPy, with repos prepared with `contrib/discovery-helper.sh 50 100`, this gives a slight improvement (around 0.5% on wall time, but 10% on CPU) before: ! wall 0.172801 comb 0.180000 user 0.180000 sys 0.000000 (median of 541) after: ! wall 0.171798 comb 0.160000 user 0.160000 sys 0.000000 (median of 551) (perf command run time upped because of bigger variability during this test). Differential Revision: https://phab.mercurial-scm.org/D5945
author Georges Racinet <georges.racinet@octobus.net>
date Mon, 04 Feb 2019 19:46:57 +0100
parents 47881d2a9d99
children 3bdb21bbf791
comparison
equal deleted inserted replaced
41716:977432970080 41717:9060af281be7
44 iter_revs: impl Clone + Iterator<Item = &'a Revision>, 44 iter_revs: impl Clone + Iterator<Item = &'a Revision>,
45 ) -> Result<HashSet<Revision>, GraphError> { 45 ) -> Result<HashSet<Revision>, GraphError> {
46 let mut heads: HashSet<Revision> = iter_revs.clone().cloned().collect(); 46 let mut heads: HashSet<Revision> = iter_revs.clone().cloned().collect();
47 heads.remove(&NULL_REVISION); 47 heads.remove(&NULL_REVISION);
48 for rev in iter_revs { 48 for rev in iter_revs {
49 remove_parents(graph, *rev, &mut heads)?; 49 if *rev != NULL_REVISION {
50 remove_parents(graph, *rev, &mut heads)?;
51 }
50 } 52 }
51 Ok(heads) 53 Ok(heads)
52 } 54 }
53 55
54 /// Retain in `revs` only its relative heads. 56 /// Retain in `revs` only its relative heads.
69 revs.remove(&NULL_REVISION); 71 revs.remove(&NULL_REVISION);
70 // we need to construct an iterable copy of revs to avoid itering while 72 // we need to construct an iterable copy of revs to avoid itering while
71 // mutating 73 // mutating
72 let as_vec: Vec<Revision> = revs.iter().cloned().collect(); 74 let as_vec: Vec<Revision> = revs.iter().cloned().collect();
73 for rev in as_vec { 75 for rev in as_vec {
74 remove_parents(graph, rev, revs)?; 76 if rev != NULL_REVISION {
77 remove_parents(graph, rev, revs)?;
78 }
75 } 79 }
76 Ok(()) 80 Ok(())
77 } 81 }
78 82
79 #[cfg(test)] 83 #[cfg(test)]