D9022: repo: avoid copying/updating a dict on every `repo.__getitem__`

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

D9022: repo: avoid copying/updating a dict on every `repo.__getitem__`

marmoute (Pierre-Yves David)
spectral created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This has some mild performance benefits. I'm looking into a pathological case
  where one of our `hg log` invocations takes several seconds, and according to
  hyperfine this reduces the wall time of the entire operation (running in chg)
  from:
 
    Time (mean ± σ):      7.390 s ±  0.106 s    [User: 7.058 s, System: 0.271 s]
   
    Range (min … max):    7.300 s …  7.625 s
 
  to:
 
    Time (mean ± σ):      7.046 s ±  0.091 s    [User: 6.714 s, System: 0.279 s]
   
    Range (min … max):    6.916 s …  7.169 s
 
  Note: the log command is slow due to an issue in our custom stuff executing
  `repo[<arg>]` 298,800 times. This performance improvement is likely not
  noticeable during normal operation, but I don't feel like it's making the code
  more difficult to understand, and every small bit helps.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1570,7 +1570,7 @@
     def _quick_access_changeid_wc(self):
         # also fast path access to the working copy parents
         # however, only do it for filter that ensure wc is visible.
-        quick = {}
+        quick = self._quick_access_changeid_null.copy()
         cl = self.unfiltered().changelog
         for node in self.dirstate.parents():
             if node == nullid:
@@ -1609,11 +1609,9 @@
         This contains a list of symbol we can recognise right away without
         further processing.
         """
-        mapping = self._quick_access_changeid_null
         if self.filtername in repoview.filter_has_wc:
-            mapping = mapping.copy()
-            mapping.update(self._quick_access_changeid_wc)
-        return mapping
+            return self._quick_access_changeid_wc
+        return self._quick_access_changeid_null
 
     def __getitem__(self, changeid):
         # dealing with special cases



To: spectral, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel