Mercurial > hg-stable
changeset 16132:41fc1e078d68
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.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 17 Feb 2012 13:53:41 -0600 |
parents | 6f236c8bdc01 |
children | 84c58da3a1f8 |
files | mercurial/graphmod.py |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)