简体   繁体   English

如何减少此视图的渲染时间?

[英]How can I decrease the render time of this view?

It takes a long time for my view to render. 我的视图需要很长时间才能呈现。 It consists of a table populated from about 90 table records. 它由一个由大约90个表记录组成的表组成。 The dB calls are running very quickly, but it takes a while to display all the records. dB呼叫运行非常快,但是需要一段时间才能显示所有记录。 Here is the bit of code causing the sluggishness: 这是导致缓慢的代码部分:

<table>               
    @for (int i = 0; i < Model.PositionEdits.Count; i++)
    {
        <tr>
            <td>
                @Html.DisplayFor(x => x.PositionEdits[i].PositionID)
                @Html.HiddenFor(x => x.PositionEdits[i].PositionID)
            </td>
            <td>
                @Html.DisplayFor(x => x.PositionEdits[i].PositionDescr)
                @Html.HiddenFor(x => x.PositionEdits[i].Description)
            </td>
            <td>
                @*editable*@
                @Html.DropDownList("Position",
                    new SelectList(Model.Positions),
                    Model.PositionEdits[i].Position)
                @Html.HiddenFor(x => x.OldPositions[i].Position)
                @Html.HiddenFor(x => x.PositionEdits[i].Position)
            </td>
        </tr>
    }
</table>  

I realize that paginating would solve my problem, but I was hoping to show all ~90 records on the same page. 我意识到分页可以解决我的问题,但是我希望在同一页面上显示所有〜90条记录。 Is there a way I can improve this view to decrease load time? 有什么方法可以改善此视图以减少加载时间?

First and foremost, if you're still in local development, especially if you're using debug in Visual Studio, it is the absolute wrong time to worry about things like page load times. 首先,如果您仍在本地开发中,尤其是在Visual Studio中使用调试时,这是担心页面加载时间之类的事情的绝对错误时间。 You're dealing with a very light-weight single-headed server with tons of overhead caused by the integration back and forth with Visual Studio and its tooling. 您要处理的是非常轻巧的单头服务器,由于与Visual Studio及其工具的来回集成而导致大量的开销。 Page load times are meaningless. 页面加载时间没有意义。

Once you've got something workable, you can deploy it to a production-ready server environment to test performance. 一旦可行,就可以将其部署到生产就绪的服务器环境中以测试性能。 Unless you're running on full blown IIS on a dedicated web server with the actual RAM and other resources you plan to devote to the site in production, any measurement of performance is meaningless as it's out of context. 除非您要在专用Web服务器上的完整IIS上运行,并计划将其投入生产中的实际RAM和其他资源,否则对性能的任何衡量都是毫无意义的,因为它与上下文无关。

If it's still slow, which I don't see any way it possibly could be (90 records on an actual web server with full IIS with even a modest amount of system resources is trivial), you'll need to investigate what part is really slowing you down. 如果仍然很慢(我看不到任何可能的方式)(在具有完整IIS的实际Web服务器上记录了90条记录,即使只有少量的系统资源也是微不足道的),则您需要调查真正的部分放慢你的速度。 There's time involved in the initial transmission of the request, database queries, the actual server time generating a response, time to send that response back to the user, time it takes for the browser to render the HTML and CSS, issue requests/receive responses for additional resources like CSS, JS files and images, and time to execute any JS on the page. 初始传输请求,数据库查询,生成响应的实际服务器时间,将响应发送回用户的时间,浏览器呈现HTML和CSS所需的时间,发出请求/接收响应的时间了解CSS,JS文件和图像等其他资源,以及在页面上执行任何JS的时间。

Using the developer tools of your browser (Chrome has a particular good set in this regard), you should be able to see a gantt chart indicating when each request was issued and how long it took to get the response. 使用浏览器的开发人员工具(Chrome在这方面有一个特别好的设置),您应该能够看到一个甘特图,该图指示何时发出每个请求以及获取响应所需的时间。 That only tells part of the story though. 不过,这仅说明了故事的一部分。 You'll need additional tools to dig deeper once you find some problem areas to look at. 一旦发现一些问题区域,您将需要其他工具来深入研究。 I personally use Glimpse . 我个人使用Glimpse This will give you very detailed information about how long just about every part of the process took and what pieces of your application are slowing you down. 这将为您提供非常详细的信息,有关该过程每个部分花费了多长时间以及应用程序的哪些部分使您减速。 The steps you need to take to fix the problem will largely depend on what is actually causing the problem, which so far is still a mystery. 解决问题所需采取的步骤在很大程度上取决于实际导致问题的原因,到目前为止,这仍然是个谜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM