Mercurial > hg
comparison hgdemandimport/__init__.py @ 37843:670eb4fa1b86
demandimport: make module ignores a set (API)
The list of modules to ignore is used for membership testing. Yet
it is defined as a list.
Sets are more efficient for membership testing. So this commit converts
the module list to a set.
Since we took an API hit, I renamed the variable to further clarify
the change.
This appears to reduce the CPU time for running 300 invocations of
`hg log -r. -T '{rev}'` on my i7-6700K:
before: 18.64s
after: 18.44s
Differential Revision: https://phab.mercurial-scm.org/D3440
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 05 May 2018 18:41:51 -0700 |
parents | 3cfc9070245f |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
37840:853001c84114 | 37843:670eb4fa1b86 |
---|---|
19 if sys.version_info[0] >= 3: | 19 if sys.version_info[0] >= 3: |
20 from . import demandimportpy3 as demandimport | 20 from . import demandimportpy3 as demandimport |
21 else: | 21 else: |
22 from . import demandimportpy2 as demandimport | 22 from . import demandimportpy2 as demandimport |
23 | 23 |
24 # Extensions can add to this list if necessary. | 24 # Full module names which can't be lazy imported. |
25 ignore = [ | 25 # Extensions can add to this set. |
26 IGNORES = { | |
26 '__future__', | 27 '__future__', |
27 '_hashlib', | 28 '_hashlib', |
28 # ImportError during pkg_resources/__init__.py:fixup_namespace_package | 29 # ImportError during pkg_resources/__init__.py:fixup_namespace_package |
29 '_imp', | 30 '_imp', |
30 '_xmlplus', | 31 '_xmlplus', |
53 # setuptools 8 expects this module to explode early when not on windows | 54 # setuptools 8 expects this module to explode early when not on windows |
54 'distutils.msvc9compiler', | 55 'distutils.msvc9compiler', |
55 '__builtin__', | 56 '__builtin__', |
56 'builtins', | 57 'builtins', |
57 'urwid.command_map', # for pudb | 58 'urwid.command_map', # for pudb |
58 ] | 59 } |
59 | 60 |
60 _pypy = '__pypy__' in sys.builtin_module_names | 61 _pypy = '__pypy__' in sys.builtin_module_names |
61 | 62 |
62 if _pypy: | 63 if _pypy: |
63 ignore.extend([ | 64 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) |
64 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) | 65 IGNORES.add('_ctypes.pointer') |
65 '_ctypes.pointer', | |
66 ]) | |
67 | 66 |
68 demandimport.init(ignore) | 67 demandimport.init(IGNORES) |
69 | 68 |
70 # Re-export. | 69 # Re-export. |
71 isenabled = demandimport.isenabled | 70 isenabled = demandimport.isenabled |
72 disable = demandimport.disable | 71 disable = demandimport.disable |
73 deactivated = demandimport.deactivated | 72 deactivated = demandimport.deactivated |