Patchwork [3,of,3] setdiscovery: avoid calling any sample building if the undecided set is small

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 7, 2015, 9:53 p.m.
Message ID <beed36bcfeeb6a1e0e9d.1420667635@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7360/
State Accepted
Commit c3cd8755df00bf786eeab9da57a195c596a99d48
Headers show

Comments

Pierre-Yves David - Jan. 7, 2015, 9:53 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1420591233 28800
#      Tue Jan 06 16:40:33 2015 -0800
# Node ID beed36bcfeeb6a1e0e9d7c8e170ad981d02d621e
# Parent  44506b02be8e38d74bf1ad2fec4ff2f8421ea61a
setdiscovery: avoid calling any sample building if the undecided set is small

If the length of undecided is smaller than the sample size, we can just request
information for all all them.

This conditional was previously handled by '_setupsample'. But '_setupsample' is
in my opinions a problematic function with blurry semantic. Having this
conditional explicitly earlier make the code more explicit and move us closer
to removing this '_setupsample' function.
Matt Mackall - Jan. 7, 2015, 10:38 p.m.
On Wed, 2015-01-07 at 13:53 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1420591233 28800
> #      Tue Jan 06 16:40:33 2015 -0800
> # Node ID beed36bcfeeb6a1e0e9d7c8e170ad981d02d621e
> # Parent  44506b02be8e38d74bf1ad2fec4ff2f8421ea61a
> setdiscovery: avoid calling any sample building if the undecided set is small

These are queued for default, thanks.

Patch

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -72,12 +72,10 @@  def _updatesample(dag, nodes, sample, al
             if not nodes or p in nodes:
                 dist.setdefault(p, d + 1)
                 visit.append(p)
 
 def _setupsample(dag, nodes, size):
-    if len(nodes) <= size:
-        return set(nodes), None, 0
     always = dag.headsetofconnecteds(nodes)
     desiredlen = size - len(always)
     if desiredlen <= 0:
         # This could be bad if there are very many heads, all unknown to the
         # server. We're counting on long request support here.
@@ -203,12 +201,15 @@  def findcommonheads(ui, local, remote,
         else:
             # use even cheaper initial sample
             ui.debug("taking quick initial sample\n")
             samplefunc = _takequicksample
             targetsize = initialsamplesize
-        sample = samplefunc(dag, undecided, targetsize)
-        sample = _limitsample(sample, targetsize)
+        if len(undecided) < targetsize:
+            sample = list(undecided)
+        else:
+            sample = samplefunc(dag, undecided, targetsize)
+            sample = _limitsample(sample, targetsize)
 
         roundtrips += 1
         ui.progress(_('searching'), roundtrips, unit=_('queries'))
         ui.debug("query %i; still undecided: %i, sample size is: %i\n"
                  % (roundtrips, len(undecided), len(sample)))