问题
I used miniprofiler for my page because I think I have big loading time for my first page and some other pages. I am starting with miniprofiler but I think it is very good tool. I have this result:
http://localhost:50783/
192.2 +0.0- Getting articles from database 2.2 +186.9
- Find: Index 866.4 +190.9
- Render : Index 1839.0 +1058.1
- Find: _Article 530.0 +2809.0
- Render partial: _Article 64.3 +3339.2
- Render partial: _Article 8.2 +3404.2
- Render partial: _Article 12.5 +3413.0
- Render partial: _Article 8.7 +3426.2
- Render partial: _Article 7.9 +3435.4
- Render partial: _LeftMenu 64.8 +3520.4
- Render partial: _LogOnPartial 3.3 +3556.3
- Render partial: _RightMenuTest 2530.1 +3591.2
- Render partial: _NextMatch 3.5 +4088.7
- Render partial: _Standings 4.7 +4226.5
- Render partial: _Footer 21.2 +6137.4
Can anybody help me with reducing that times where is Find? What it means? I know that RightMenuTest has the biggest time and I am trying to reduce it too. I have many my own helpers there and I think that is problem with partial view _RightMenuTest. So I need help with reducing that others times.
Thank you
Edited:
_Article:
@model SkMoravanSvitavka.Models.Article
<h3>@Html.ActionLink(Model.Title, "Zobrazit", "Clanek", new { id = Model.ArticleID }, null)</h3>
<p>@Html.Raw(Html.ArticleImageToSmall(Html.Article(Model.Text))) </p>
@Html.ActionLink("Počet komentářů:" + Model.Comments.Count, "Zobrazit", "Clanek", new { id = Model.ArticleID }, null)
Index view for article:
@model IEnumerable<SkMoravanSvitavka.Models.Article>
@{
ViewBag.Title = "Sk Moravan Svitávka - oficiální stránky fotbalového klubu";
}
@if (Model != null)
{
foreach (var item in Model)
{
@Html.Partial("_Article", item);
}
}
Index in controller for article:
public ActionResult Index()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Getting articles from database"))
{
var model = repo.GetLatestArticles(5);
return View(model);
}
}
回答1:
Try to use RenderPartial insead of Partial:
foreach (var item in Model)
{
Html.RenderPartial("_Article", item);
}
回答2:
Make sure to do the tests when the project is compiled in Release mode as well. ASP MVC is known to perform extra reflection to find views in Debug mode for more comprehensive debugging capabilities.
来源:https://stackoverflow.com/questions/11519205/slow-loading-first-page-asp-net-mvc