Asp.net MVC 2 DisplayFor性能问题? [英] Asp.net Mvc 2 DisplayFor Performance Issue?

查看:176
本文介绍了Asp.net MVC 2 DisplayFor性能问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我最近的项目,该项目使用Asp.net MVC 2,我们发现,DisplayFor有性能问题。我不太确定它是否是在真正的问题还是我错过了什么?

In my recent project which is using Asp.net Mvc 2, we found that the DisplayFor has performance issue. I'm not so sure whether it is the real issue or did I miss something?

我希望有Asp.net的mvc师可以解释给我听。 :)

I hope some Asp.net Mvc Guru can explain it to me. :)

模式。

public class Customer
{
    public int CustomerId { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string EmailAddress { get; set; }

    public static IEnumerable<Customer> GetCustomers()
    {            
        for (int i = 0; i < 1000; i++)
        {
            var cust = new Customer()
            {
                CustomerId = i + 1,
                Name = "Name - " + (i + 1),
                Address = "Somewhere in the Earth...",
                EmailAddress = "customerABC"
            };

            yield return cust;
        }
    }
}

控制器

public ActionResult V1()
    {            
        return View(Customer.GetCustomers());
    }

    public ActionResult V2()
    {
        return View(Customer.GetCustomers());
    }

V1(其中有性能问题)

V1 (which has performance issue)

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Customer>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    V1
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>V1</h2>
    <table>
    <%foreach (var cust in this.Model)
      {%>
        <%= Html.DisplayFor(m => cust) %>  
      <%} %>
    </table>
</asp:Content>

和模板是

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Customer>" %>
<tr>
    <td><%= this.Model.CustomerId %></td>
    <td><%= this.Model.Name %></td>
    <td><%= this.Model.Address %></td>
    <td><%= this.Model.EmailAddress %></td>    
</tr>

V2(无性能问题)

V2 (no performance issue)

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Customer>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    V2
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>V2</h2>
    <table>
    <%foreach (var cust in this.Model)
      {%>
        <tr>
            <td><%= cust.CustomerId%></td>
            <td><%= cust.Name%></td>
            <td><%= cust.Address%></td>
            <td><%= cust.EmailAddress%></td>    
        </tr>
      <%} %>
      </table>
</asp:Content>

我可以很容易看到V1和V2之间的性能差异。

I can easy see the performance difference between V1 and V2.

修改:当我部署到我的本地IIS 7(与发行版),它(V1)变得非常快。这个问题是解决了,但我还是想知道原因。 :)

EDIT: When I deploy to my local IIS 7 (with Release version) and it (V1) becomes very fast. The issue is solved, but I still want to know the reason. :)

谢谢,结果
梭萌

Thanks,
Soe Moe

推荐答案

缓存仅在释放模式启用。如果您运行在调试模式下的应用程序,你可能会看到由于磁盘访问的性能损失。

Caching is enabled only in release mode. If you run the application in debug mode, you might see a performance hit due to disk accesses.

另请参阅:
<一href=\"http://$c$cclimber.net.nz/archive/2009/04/22/how-to-improve-htmlhelper.renderpartial-performances-donrsquot-run-in-debug-mode.aspx\" rel=\"nofollow\">http://$c$cclimber.net.nz/archive/2009/04/22/how-to-improve-htmlhelper.renderpartial-performances-donrsquot-run-in-debug-mode.aspx

这篇关于Asp.net MVC 2 DisplayFor性能问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆