Suppose we have the following code:
ExpressionHelper.GetRouteValuesFromExpression<AccountController>(ax => ax.MyAction("a", "b"));
(from ASP.NET MVC Futures assembly). Method is reasonably fast - it executes 10k iterations in 150ms.
Now, we change code to this:
string a = "a";
string b = "b";
ExpressionHelper.GetRouteValuesFromExpression<AccountController>(ax => ax.MyAction(a, b));
This code will execute 10k iterations in 15 seconds
The problem is the following code:
Expression<Func<object>> lambdaExpression = Expression.Lambda<Func<object>>(Expression.Convert(arg, typeof (object)));
Func<object> func = lambdaExpression.Compile();
value = func()
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.