Patchwork D8585: scmutil: speed up relativization of paths when it's a no-op

login
register
mail settings
Submitter phabricator
Date May 26, 2020, 11:19 a.m.
Message ID <differential-rev-PHID-DREV-mmpkompva2ngxctwedq3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46378/
State Superseded
Headers show

Comments

phabricator - May 26, 2020, 11:19 a.m.
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Running commands from the root is commmon, in particular for
  automation. Running `hg files > /tmp/a` from the root of
  mozilla-central on linux:
  
  before:
  real	0m1,510s
  user	0m1,387s
  sys	0m0,090s
  
  after:
  real	0m1,266s
  user	0m1,165s
  sys	0m0,073s
  
  (there are 280k paths, so this was costing ~1us per path somehow)

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -803,9 +803,12 @@ 
 
     if relative:
         cwd = repo.getcwd()
-        pathto = repo.pathto
-        return lambda f: pathto(f, cwd)
-    elif repo.ui.configbool(b'ui', b'slash'):
+        if cwd != b'':
+            # this branch is correct when cwd == b'', ie cwd = repo root,
+            # but it's slower
+            pathto = repo.pathto
+            return lambda f: pathto(f, cwd)
+    if repo.ui.configbool(b'ui', b'slash'):
         return lambda f: f
     else:
         return util.localpath