ASP.NET MVC渲染似乎很慢 [英] ASP.NET MVC rendering seems slow
问题描述
我已经在Visual Studio中创建了一个全新的MVC4 Web应用程序,并且除了为其添加Home控制器和"Hello world"索引视图外,还没有做其他任何事情.然后,我安装了MiniProfiler NuGet软件包,并将必要的几行放在_Layout.cshtml
中.当我以发布模式(在IIS中托管)运行网站时,这就是我得到的:
I've created a brand new MVC4 web application in Visual Studio, and done nothing more with it than add a Home controller and a "Hello world" index view for it. I then installed the MiniProfiler NuGet package and put the necessary couple of lines in _Layout.cshtml
. This is what I get when I run the site in Release mode (hosted in IIS):
渲染时间因页面加载而异,但130ms差不多快了.这对我来说似乎有点慢,因为我看到其他人以30毫秒或更短的时间渲染页面.有什么主意为什么使用全新的空MVC4项目会如此缓慢地渲染?我的处理器是Intel Core i5-2400,该计算机具有16GB RAM.
The rendering time varies by pageload, but 130ms is about as fast as it gets. This seems a bit slow to me, as I've seen other people who get pages rendered in 30ms or quicker. Any ideas why the rendering would be this slow with a brand new empty MVC4 project? My processor is an Intel Core i5-2400 and the machine has 16GB RAM.
顺便说一句,这不是第一次加载页面.在获得此130ms的结果之前,我重新加载了页面几次.
By the way, this is not the first time the page is loaded; I reloaded the page a few times before getting this 130ms result.
更新:
我遵循了PSCoder的答案中的建议(删除了所有RazorViewEngine,但将其减少了一半):
UPDATE:
I followed the advice in the answer from PSCoder (remove all but the RazorViewEngine), and it halved the rendering time:
这确实很好,但是页面的主要Render
操作仍能获得约70ms或更高的时间;理想情况下,我希望将其减半或更好.
This is really good, but I still get about 70ms or higher for the main Render
action of the page; ideally I'd like to halve that or better.
具体来说,我想问一下:
Specifically, I'd like to ask:
- 此渲染时间似乎过慢还是在我的计算机上平均?
- 有什么办法可以加快速度吗?
推荐答案
这可以帮助改善与ASP.NET MVC相关的性能问题,您可以做的一项性能改进就是清除所有视图引擎并添加一个.您使用的.例如:-RazorViewEngine
. MVC默认情况下会注册2个视图引擎Webforms
和Razor
视图引擎,因此清除并添加单独使用的视图引擎将提高查找性能.
This could help improve ASP.NET MVC related performance issue , one performance improvement that you can do is to clear all the view engines and add the one(s) that you use. say for ex:- RazorViewEngine
. MVC registers 2 view engines by default Webforms
and Razor
view engines, so clearing and adding the ones that is used alone will improve the look up performance.
您可以在global.asax
Application_Start
中添加它.
You can add this in global.asax
Application_Start
.
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
为了完全利用视图查找缓存,从而再次提高性能,请在发布模式下编译代码,并确保为web.config
文件配置了<compilation debug="false" />
以便可以启动视图查找缓存.
In order to completely utilize view look up caching and thus again performance gain compile the code in release mode and make sure that your web.config
file is configured with <compilation debug="false" />
for view look up caching to kick in.
这篇关于ASP.NET MVC渲染似乎很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!