comparison contrib/perf.py @ 37890:8fb9985382be

pycompat: export queue module instead of symbols in module (API) Previously, pycompat and util re-exported individual symbols from the queue module. This had the side-effect of forcing the loading of the queue module whenever pycompat/util was imported. These symbols aren't used very often. So importing the module to get a handle on the symbols is wasteful. This commit changes pycompat so it no longer exports the individual symbols in the queue module. Instead, we make the imported module a "public" symbol. We drop the individual symbol aliases from the util module. All consumers are updated to use pycompat.queue.* instead. This change makes 300 invocations of `hg log -r. -T '{rev}\n'` a little faster: before: 18.44s after: 17.87s Differential Revision: https://phab.mercurial-scm.org/D3441
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 05 May 2018 18:35:16 -0700
parents 5bcd5859b505
children 1b121cc680f2
comparison
equal deleted inserted replaced
37889:670eb4fa1b86 37890:8fb9985382be
68 from mercurial import pycompat 68 from mercurial import pycompat
69 getargspec = pycompat.getargspec # added to module after 4.5 69 getargspec = pycompat.getargspec # added to module after 4.5
70 except (ImportError, AttributeError): 70 except (ImportError, AttributeError):
71 import inspect 71 import inspect
72 getargspec = inspect.getargspec 72 getargspec = inspect.getargspec
73
74 try:
75 # 4.7+
76 queue = pycompat.queue.Queue
77 except (AttributeError, ImportError):
78 # <4.7.
79 try:
80 queue = pycompat.queue
81 except (AttributeError, ImportError):
82 queue = util.queue
73 83
74 # for "historical portability": 84 # for "historical portability":
75 # define util.safehasattr forcibly, because util.safehasattr has been 85 # define util.safehasattr forcibly, because util.safehasattr has been
76 # available since 1.9.3 (or 94b200a11cf7) 86 # available since 1.9.3 (or 94b200a11cf7)
77 _undefined = object() 87 _undefined = object()
1027 elif blocks: 1037 elif blocks:
1028 mdiff.bdiff.blocks(*pair) 1038 mdiff.bdiff.blocks(*pair)
1029 else: 1039 else:
1030 mdiff.textdiff(*pair) 1040 mdiff.textdiff(*pair)
1031 else: 1041 else:
1032 q = util.queue() 1042 q = queue()
1033 for i in xrange(threads): 1043 for i in xrange(threads):
1034 q.put(None) 1044 q.put(None)
1035 ready = threading.Condition() 1045 ready = threading.Condition()
1036 done = threading.Event() 1046 done = threading.Event()
1037 for i in xrange(threads): 1047 for i in xrange(threads):