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.
--- 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)