rust-discovery: optimization of add commons/missings for empty arguments
authorGeorges Racinet on percheron.racinet.fr <georges@racinet.fr>
Tue, 21 May 2019 12:46:38 +0200
changeset 42744 c5748c6969b9
parent 42743 8c9a6adec67a
child 42745 4d20b1fe8a72
rust-discovery: optimization of add commons/missings for empty arguments These two cases have to be catched early for different reasons. In the case of add_missing_revisions, we don't want to trigger the computation of the undecided set (and the children cache) too early: the later the better. In the case of add_common_revisions, the inner `MissingAncestors` object wouldn't know that all ancestors of its bases have already been removed from the undecided. In principle, that would in itself be a lead for further improvement: this remove_ancestors_from could be more incremental, but the current performance seems to be good enough. Differential Revision: https://phab.mercurial-scm.org/D6429
rust/hg-core/src/discovery.rs
--- a/rust/hg-core/src/discovery.rs	Tue Apr 16 01:16:39 2019 +0200
+++ b/rust/hg-core/src/discovery.rs	Tue May 21 12:46:38 2019 +0200
@@ -225,7 +225,11 @@
         &mut self,
         common: impl IntoIterator<Item = Revision>,
     ) -> Result<(), GraphError> {
+        let before_len = self.common.get_bases().len();
         self.common.add_bases(common);
+        if self.common.get_bases().len() == before_len {
+            return Ok(());
+        }
         if let Some(ref mut undecided) = self.undecided {
             self.common.remove_ancestors_from(undecided)?;
         }
@@ -246,11 +250,14 @@
         &mut self,
         missing: impl IntoIterator<Item = Revision>,
     ) -> Result<(), GraphError> {
+        let mut tovisit: VecDeque<Revision> = missing.into_iter().collect();
+        if tovisit.is_empty() {
+            return Ok(());
+        }
         self.ensure_children_cache()?;
         self.ensure_undecided()?; // for safety of possible future refactors
         let children = self.children_cache.as_ref().unwrap();
         let mut seen: HashSet<Revision> = HashSet::new();
-        let mut tovisit: VecDeque<Revision> = missing.into_iter().collect();
         let undecided_mut = self.undecided.as_mut().unwrap();
         while let Some(rev) = tovisit.pop_front() {
             if !self.missing.insert(rev) {