Patchwork [4,of,8] bookmarks: prefetch 'lookup' outside of the loop

login
register
mail settings
Submitter Pierre-Yves David
Date June 8, 2017, 7:44 p.m.
Message ID <656b0fe395c5592e073f.1496951060@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21254/
State Accepted
Headers show

Comments

Pierre-Yves David - June 8, 2017, 7:44 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1496859662 -3600
#      Wed Jun 07 19:21:02 2017 +0100
# Node ID 656b0fe395c5592e073faa5c0fd95c5c56a0676c
# Parent  1aac1d0629978bad92aca55dd47ee3ba7c28465c
# EXP-Topic perf
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 656b0fe395c5
bookmarks: prefetch 'lookup' outside of the loop

Skipping the attribute lookup up raise a significant speedup.

Example on a repository with about 4000 bookmarks.

Before:
! wall 0.026027 comb 0.020000 user 0.020000 sys 0.000000 (best of 112)
After:
! wall 0.021580 comb 0.020000 user 0.020000 sys 0.000000 (best of 134)

(This is also in its own changeset to clarify the perf win from another coming
changesets)

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -50,6 +50,7 @@  class bmstore(dict):
     def __init__(self, repo):
         dict.__init__(self)
         self._repo = repo
+        lookup = repo.changelog.lookup
         try:
             bkfile = _getbkfile(repo)
             for line in bkfile:
@@ -63,7 +64,7 @@  class bmstore(dict):
                 sha, refspec = line.split(' ', 1)
                 refspec = encoding.tolocal(refspec)
                 try:
-                    self[refspec] = repo.changelog.lookup(sha)
+                    self[refspec] = lookup(sha)
                 except LookupError:
                     pass
         except IOError as inst: