Patchwork D1499: hbisect: use a defaultdict to avoid large allocations for a large changelogs

login
register
mail settings
Submitter phabricator
Date Nov. 23, 2017, 10:24 p.m.
Message ID <differential-rev-PHID-DREV-6lyevt5trithyqxa64jy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25731/
State Superseded
Headers show

Comments

phabricator - Nov. 23, 2017, 10:24 p.m.
dsp created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We can avoid a SPACE(len(changelog)) allocation by using a defaultdict.

TEST PLAN
    python run-tests.py test-bisect*

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1499

AFFECTED FILES
  mercurial/hbisect.py

CHANGE DETAILS




To: dsp, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 25, 2017, 3:42 a.m.
yuja added a comment.


  Queued, thanks. I don't have any number, but this seems good for a common
  scenario in which a small part of a large repository will be bisected.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1499

To: dsp, #hg-reviewers, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -38,7 +38,7 @@ 
 
     def buildancestors(bad, good):
         badrev = min([changelog.rev(n) for n in bad])
-        ancestors = [None] * (len(changelog) + 1)
+        ancestors = collections.defaultdict(lambda: None)
         for rev in repo.revs("descendants(%ln) - ancestors(%ln)", good, good):
             ancestors[rev] = []
         if ancestors[badrev] is None: