I have a page that has a bunch of widgets on it. Each widget is a view. Right now the widget rendering is done in a foreach loop like so.
public class WidgetCollection : List<Widget>, IPersonalizable
{
public void Render(HtmlHelper html)
{
foreach (Widget w in this)
{
html.RenderAction("Default", "Widget", new { model = w });
}
}
But that means that some of my widgets that render in 800ms because they’re IO bound are blocking a bunch of other widgets than only take 100ms to render. So in total the time it takes to render the page is about 3 seconds. I want the page to render in just a bit over 800ms or as close as possible to that.
One idea I had was to call html.Action() to get a string value for each action in parallel but MVC doesn’t seem to like rendering views in parallel. I always get an “Object not set to the instance of an object” error when I attempt to do it. The error comes from deep in the MVC stack so I think it is just an MVC bug.
Does anyone have a better idea for increasing page rendering speed?
Paul,
There is a
AsyncControllerclass that your base controllers can inherit from. that may be your best bet.i.e.
this link may shed further light: http://msdn.microsoft.com/en-us/library/ee728598.aspx
or this one: http://bartwullems.blogspot.com/2010/01/using-asynccontroller-in-aspnet-mvc-2.html
You’d then use it either with ajax or directly, given that it’s async.
jim