Patchwork D8092: hghave: cache the result of gethgversion

login
register
mail settings
Submitter phabricator
Date Feb. 7, 2020, 3:02 p.m.
Message ID <differential-rev-PHID-DREV-jirosl3kkpidkc4syhxc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45020/
State Superseded
Headers show

Comments

phabricator - Feb. 7, 2020, 3:02 p.m.
jcristau created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  hghave --test-features calls it 90 times, each one calling hg --version
  which takes a tenth of a second on my workstation, adding up to about
  10s win on test-hghave.t.
  
  Fixes https://bugs.debian.org/939756

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/hghave.py

CHANGE DETAILS




To: jcristau, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 7, 2020, 6:52 p.m.
marmoute added a comment.


  I can confirm the perf win:
  
  before: 10.687  seconds
  after 3.6.19 seconds

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8092/new/

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

To: jcristau, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Feb. 7, 2020, 8:21 p.m.
pulkit added a comment.


  This is fixing some debian packaging issue, so is it targeted for stable branch?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8092/new/

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

To: jcristau, #hg-reviewers, marmoute
Cc: pulkit, marmoute, mercurial-devel
phabricator - Feb. 7, 2020, 8:33 p.m.
jcristau added a comment.


  It fixes a longstanding issue in tests, it's not particularly urgent IMO.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8092/new/

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

To: jcristau, #hg-reviewers, marmoute
Cc: pulkit, marmoute, mercurial-devel

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -307,13 +307,21 @@ 
         return False
 
 
-def gethgversion():
+def _gethgversion():
     m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
     if not m:
         return (0, 0)
     return (int(m.group(1)), int(m.group(2)))
 
 
+_hgversion = None
+def gethgversion():
+    global _hgversion
+    if _hgversion is None:
+        _hgversion = _gethgversion()
+    return _hgversion
+
+
 @checkvers(
     "hg", "Mercurial >= %s", list([(1.0 * x) / 10 for x in range(9, 99)])
 )