From patchwork Tue Sep 11 23:02:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,6] ancestor: use heapreplace() in place of heappop/heappush() From: Yuya Nishihara X-Patchwork-Id: 34508 Message-Id: <5756061e6a5401823071.1536706931@mimosa> To: mercurial-devel@mercurial-scm.org Date: Wed, 12 Sep 2018 08:02:11 +0900 # HG changeset patch # User Yuya Nishihara # Date 1536586459 -32400 # Mon Sep 10 22:34:19 2018 +0900 # Node ID 5756061e6a540182307184da3742eedce7a8706d # Parent a7b608b84035fcd1d25ca9bac3c8b1cfb1b7f4c3 ancestor: use heapreplace() in place of heappop/heappush() This should be slightly faster. Overall perfancestors result:: cpython nginx mercurial ------------- ---------------- ---------------- ---------------- b6db2e80a9ce^ 0.103461 0.006303 0.035716 8eb2145ff0fb 0.192307 (x1.86) 0.012115 (x1.92) 0.052135 (x1.46) this patch 0.139986 (x1.35) 0.006389 (x1.01) 0.037176 (x1.04) diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py --- a/mercurial/ancestor.py +++ b/mercurial/ancestor.py @@ -264,6 +264,7 @@ def _lazyancestorsiter(parentrevs, initr seen = {nullrev} heappush = heapq.heappush heappop = heapq.heappop + heapreplace = heapq.heapreplace see = seen.add if inclusive: @@ -294,8 +295,7 @@ def _lazyancestorsiter(parentrevs, initr if current - p1 == 1: visit[0] = -p1 else: - heappop(visit) - heappush(visit, -p1) + heapreplace(visit, -p1) see(p1) else: heappop(visit)