<p>Suppose we have the following code:</p>

<pre><code>ExpressionHelper.GetRouteValuesFromExpression&lt;AccountController&gt;(ax =&gt; ax.MyAction("a", "b"));
</code></pre>

<p>(from ASP.NET MVC Futures assembly). Method is reasonably fast - it executes 10k iterations in 150ms.</p>

<p>Now, we change code to this:</p>

<pre><code>string a = "a";
string b = "b";
ExpressionHelper.GetRouteValuesFromExpression&lt;AccountController&gt;(ax =&gt; ax.MyAction(a, b));
</code></pre>

<p>This code will execute 10k iterations in 15 <strong>seconds</strong></p>

<p>The problem is the following code:</p>

<pre><code>Expression&lt;Func&lt;object&gt;&gt; lambdaExpression = Expression.Lambda&lt;Func&lt;object&gt;&gt;(Expression.Convert(arg, typeof (object)));

Func&lt;object&gt; func = lambdaExpression.Compile();

value = func()
</code></pre>

<p>Is there a better way to get value from expression than compiling expression every time? This can greatly affect ASP.NET MVC link generation speed.</p>

Why don't you just cache the value of the expression and its compiled value locally if this is such a bottleneck? I imagine a simply Dictionary could do the trick:
```
```
Dictionary<Expression<Action<T>>, Action<T>> m_Cache =
    new Dictionary<Expression<Action<T>>, Action<T>>();

public void GetRouteValuesFromExpression<T>(Expression<Action<T>> expr) {
    Action<T> compiled = null;
    if (!m_Cache.TryGetValue(expr, ref compiled)) {
        compiled = expr.Compile();
        m_Cached.Add(expr, compiled);
    }
    // execute …
}
```
```