Commit 3d968dce authored by Yusei Tahara's avatar Yusei Tahara

buildout.py: Optimize _install_and_load by using cache.

_install_and_load is slow, using cache saves time when there are many sections.
parent 95fa0f3d
...@@ -1343,9 +1343,15 @@ class Buildout(DictMixin): ...@@ -1343,9 +1343,15 @@ class Buildout(DictMixin):
def __len__(self): def __len__(self):
return len(self._raw) return len(self._raw)
_install_and_load_cache = {}
def _install_and_load(spec, group, entry, buildout): def _install_and_load(spec, group, entry, buildout):
__doing__ = 'Loading recipe %r.', spec __doing__ = 'Loading recipe %r.', spec
try:
return _install_and_load_cache[(spec, group, entry)]
except KeyError:
pass
try: try:
req = pkg_resources.Requirement.parse(spec) req = pkg_resources.Requirement.parse(spec)
...@@ -1372,8 +1378,10 @@ def _install_and_load(spec, group, entry, buildout): ...@@ -1372,8 +1378,10 @@ def _install_and_load(spec, group, entry, buildout):
) )
__doing__ = 'Loading %s recipe entry %s:%s.', group, spec, entry __doing__ = 'Loading %s recipe entry %s:%s.', group, spec, entry
return pkg_resources.load_entry_point( result = pkg_resources.load_entry_point(
req.project_name, group, entry) req.project_name, group, entry)
_install_and_load_cache[(spec, group, entry)] = result
return result
except Exception: except Exception:
v = sys.exc_info()[1] v = sys.exc_info()[1]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment