obsolete: make _computeobsoleteset much faster
authorLaurent Charignon <lc2817@columbia.edu>
Wed, 13 Jan 2016 21:52:26 -0800
changeset 27784 432242f41d9f
parent 27783 1d095371de47
child 27785 ba427b51f1d8
obsolete: make _computeobsoleteset much faster This patch makes _computeobsoleteset much faster by looping over the draft and secrets as opposed to looping over the successors. This works because "number of draft and secret" is typically way smaller(<100) than the number of successor in the repo (~90k in my checkout of core mercurial as of today). And also because it is very fast to compute "not public()". I timed the code with the following setup: """ from mercurial import hg, ui, obsolete ui = ui.ui() repo = hg.repository(ui, "~/hg") l = repo.obsstore.successors # This caches the result """ With about 90k successors. k=obsolete._computeobsoleteset(repo) before this patch: 10 loops, best of 3: 33.9 ms per loop k=obsolete._computeobsoleteset(repo) after this patch: 10000 loops, best of 3: 83.3 µs per loop
mercurial/obsolete.py
--- a/mercurial/obsolete.py	Tue Jan 12 08:34:38 2016 +0000
+++ b/mercurial/obsolete.py	Wed Jan 13 21:52:26 2016 -0800
@@ -1119,12 +1119,11 @@
 def _computeobsoleteset(repo):
     """the set of obsolete revisions"""
     obs = set()
-    getrev = repo.changelog.nodemap.get
-    getphase = repo._phasecache.phase
-    for n in repo.obsstore.successors:
-        rev = getrev(n)
-        if rev is not None and getphase(repo, rev):
-            obs.add(rev)
+    getnode = repo.changelog.node
+    notpublic = repo.revs("not public()")
+    for r in notpublic:
+        if getnode(r) in repo.obsstore.successors:
+            obs.add(r)
     return obs
 
 @cachefor('unstable')