summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-12-13 15:35:11 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-12-13 15:35:11 +0000
commit301b7937b5c39e3121ba528f414fe53efb8086cd (patch)
treef4c44a0416c35029e4153d33eeff60009ce142ce
parentd63c97a0bef1cd2f03ca266acda67cad065632df (diff)
downloadmorph-301b7937b5c39e3121ba528f414fe53efb8086cd.tar.gz
Cache resolved refs and morphologies when traversing morphs
This cuts down on the number of HTTP requests made while computing th build order (> create source pool > traverse morphs). In an example system I was building this patch reduced the requests from 501 to 195, reducing the time to building the first chunk from 123s to 18s.
-rwxr-xr-xmorphlib/app.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 0a11c716..d154f8b9 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -292,15 +292,29 @@ class Morph(cliapp.Application):
self)
queue = collections.deque(triplets)
updated_repos = set()
+ resolved_refs = {}
+ resolved_morphologies = {}
while queue:
reponame, ref, filename = queue.popleft()
update_repo = update and reponame not in updated_repos
- absref, tree = self.resolve_ref(lrc, rrc, reponame, ref,
- update_repo)
+
+ # Resolve the (repo, ref) reference, cache result.
+ reference = (reponame, ref)
+ if not reference in resolved_refs:
+ resolved_refs[reference] = self.resolve_ref(
+ lrc, rrc, reponame, ref, update_repo)
+ absref, tree = resolved_refs[reference]
+
updated_repos.add(reponame)
- morphology = morph_factory.get_morphology(
- reponame, absref, filename)
+
+ # Fetch the (repo, ref, filename) morphology, cache result.
+ reference = (reponame, absref, filename)
+ if not reference in resolved_morphologies:
+ resolved_morphologies[reference] = \
+ morph_factory.get_morphology(reponame, absref, filename)
+ morphology = resolved_morphologies[reference]
+
visit(reponame, ref, filename, absref, tree, morphology)
if morphology['kind'] == 'system':
queue.extend((s['repo'], s['ref'], '%s.morph' % s['morph'])