MVC T4 是否会影响 ASP.NET MVC 应用程序性能?
我今天刚开始使用 MVC T4,我真的很想继续使用,但有一些事情让我烦恼。 我的应用程序相当大,所以我想知道 MVC T4 是否会损害我的 ASP.NET MVC 应用程序的性能。 我可以依赖 MVC T4 吗?
提前致谢。
I just started today to use MVC T4 and I really want to keep using, but there's something that is annoying me.
My application is quite big, so I was wondering whether MVC T4 will harm the performance of my ASP.NET MVC application.
Can I rely on MVC T4?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
T4 模板(通常)在编译时运行。因此,您的应用程序不会产生运行时成本。
T4 templates are (usually) run at compile-time. So there will not be a runtime cost to your application.
您不必担心生成的代码量。 .NET 运行时旨在高效地处理比 T4MVC 生成的内容更多的内容。
相反,您应该只担心生成的语法“糖”对 MVC 应用程序的运行时行为的影响。具体来说,我讨论的是使用 t4mvc 模式可能会迫使 MVC 使用效率较低的方式来实现某些功能的情况。 (假设的一个例子是
return View(Views.InvalidOwner);
的效率低于return View("InvalidOwner");
) 示例页面我看不到任何明显的风险。但是,如果您担心,您当然应该测量应用程序的性能。观看此视频< /a> 因为它提供了一些有关如何(甚至是否)对 MVC 应用程序进行性能优化的重要信息。
You should not worry about the ammount of code that gets generated. The .NET runtime is designed to efficiently crunch through a lot more than what T4MVC generates.
Instead, you should only worry about the impact that the generated syntactic "sugars" have on the runtime behavior of the MVC application. Specifically I'm talking about a case where using a t4mvc pattern might force MVC to use a less efficient way of achieving some functionality. (A hypothetical example of this would be where doing
return View(Views.InvalidOwner);
would be less efficient thanreturn View("InvalidOwner");
)After looking through the samples page I can't see anything that would stand out as a risk. However, if you are worried you should certainly measure the performance of your application. Take a look at this video as it provides some great information on how (and even if) to do performance optimization of MVC applications.