Patchwork [03,of,13] revlog: early return in _slicechunk when density is already good

login
register
mail settings
Submitter Boris Feld
Date July 10, 2018, 1:27 p.m.
Message ID <639f8b092c12960f1a5f.1531229232@FB-lair>
Download mbox | patch
Permalink /patch/32741/
State Accepted
Headers show

Comments

Boris Feld - July 10, 2018, 1:27 p.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@octobus.net>
# Date 1529413438 -7200
#      Tue Jun 19 15:03:58 2018 +0200
# Node ID 639f8b092c12960f1a5f196326149099f98eb8db
# Parent  14c3643ceaf460b75dcd57866c5e5eca18e842d1
# EXP-Topic write-for-sparse-read
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 639f8b092c12
revlog: early return in _slicechunk when density is already good

We don't need to do anything if we know we won't enter the second while loop.
Save the overhead of the first loop by returning earlier.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -234,6 +234,10 @@  def _slicechunk(revlog, revs):
     else:
         density = 1.0
 
+    if density >= revlog._srdensitythreshold:
+        yield revs
+        return
+
     # Store the gaps in a heap to have them sorted by decreasing size
     gapsheap = []
     heapq.heapify(gapsheap)