I was using Html.RenderPartial to loop out a Filestructure. (Parents have children that can have children ...).
<% foreach (var entry in Model) { %>
<li>
<span class="Clickable"><%=entry.Name%></span>
<% if (entry.Children.Any())
Html.RenderPartial("../FileEntry/Item.ascx", entry.Children);
%>
</li>
<% } %>
</ul>
This worked flawlessy on small data-amouns but when the tree contained over 500 entries the page took over 5-10 seconds to load.
My first thought was of course that the database query was slow, I fired up NHProf only to find out that the query took 50ms.
My memory then told me that I had read a blog post about the performance isnt all that good on Html.RenderPartial. I googled a bit but didnt really find a solution for it, so I tried to change the way I locate the view. I changed the Html.RenderPartial part of the code from
Html.RenderPartial("../FileEntry/Item.ascx", entry.Children);
to
Html.RenderPartial("~/Views/FileEntry/Item.ascx", entry.Children);
and the page once again took under 1 second to load. Pretty impressive performance boost with a one-line change.
The culprit of the problem is probably when searching for the view on the current filesystem. It probably looks in the "Shared"-folders, dont find it, look somewhere else til it finds the correct one. Hitting the filesystem *is* expansive, especially over 500 times.