# HG changeset patch # User Matt Mackall # Date 1329508421 21600 # Node ID 41fc1e078d6822502277ac80325ec3db99707a6f # Parent 6f236c8bdc01b4ddb7c6b3528284b0f1ba425d26 graphmod: add config cache Before, we'd lookup the branch for every edge segment in the entire graph: extremely expensive. This happened even when no per-branch settings existed. Now we define a revision -> config cache function that's LRU-cached and is a no-op when no configuration exists. Still not terribly fast, but hopefully only one real branch lookup per revision. This might degenerate for wide graphs as the LRU is hard-coded to 20 elements. diff -r 6f236c8bdc01 -r 41fc1e078d68 mercurial/graphmod.py --- a/mercurial/graphmod.py Fri Feb 17 13:53:19 2012 -0600 +++ b/mercurial/graphmod.py Fri Feb 17 13:53:41 2012 -0600 @@ -18,6 +18,7 @@ """ from mercurial.node import nullrev +import util CHANGESET = 'C' @@ -94,6 +95,10 @@ elif setting == "color" and val.isalnum(): config.setdefault(branch, {})[setting] = val + if config: + getconf = util.lrucachefunc(lambda rev: config.get(repo[rev].branch())) + else: + getconf = lambda rev: None for (cur, type, data, parents) in dag: @@ -125,12 +130,12 @@ if eid in next: edges.append(( ecol, next.index(eid), colors[eid], - config.get(repo[eid].branch(), None))) + getconf(eid))) elif eid == cur: for p in parents: edges.append(( ecol, next.index(p), color, - config.get(repo[p].branch(), None))) + getconf(p))) # Yield and move on yield (cur, type, data, (col, color), edges)