VS的RenderAction性能的RenderPartial [英] RenderAction vs RenderPartial performance

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

问题描述

据布拉德·威尔逊的RenderAction的的比的RenderPartial慢。

According to Brad Wilson, RenderAction is slower than RenderPartial.

但是,有没有人得到了,显示性能上的差异的统计数字?

However, has anyone got any statistics that show the difference in performance?

我在那里开发页面组成的部件的应用程序的过程。

I'm in the process of developing an application where pages are composed of "Widgets".

我有两个选择:

成分在视图级别

呼叫为的RenderAction每个插件。这是迄今为止最简单的方法但并不意味着我们对每个插件执行完整的MVC周期。

Call RenderAction for each widget. This is by far the easiest approach but does mean that we're performing a full MVC cycle for each widget.

成分在控制器级别

构成一个视图模型为包含我们需要为每个插件的数据的页面。打电话的RenderPartial为每个插件。这是更为复杂的实现但并不意味着我们将让只有一个MVC周期。

Compose one ViewModel for the page that contains the data we need for each widget. Call RenderPartial for each widget. This is much more complicated to implement but does mean we'll make only one MVC cycle.

我测试一个页面上有3个不同的小部件上面的方法和差异渲染时间为第二(几乎不值得担心)。

I tested the above approaches with 3 different widgets on a page and the difference in render time was 10ths of a second (hardly worth worrying about).

但是,有没有人有任何的测试结果比这更具体,或者想体验这两种方式?

However, has anyone got any test results more concrete than this, or perhaps experience trying both approaches?

推荐答案

我建议2更多的选择,都需要撰写的控制器级视图模型两者可以一起工作(具体取决于数据)

I'd suggest 2 more options, both require to compose the view model at Controller level and both can work together (depending on the data)


  1. Html.DisplayFor() - 显示模板

  2. 通过扩展方法助手

选项2的作品非常好,如果你想保持这些部件在不同的组件,毕竟他们只是函数返回一个字符串。我认为它也有最佳的性能,当然你失去了设计师友好的模板。我觉得要考虑可维护性方面,不仅原始性能(直到你真的需要它,即使这样,缓存是比较有用)是很重要的。

Option 2 works very well if you want to keep those widgets in different assemblies, after all they're just functions returning a string. I think it has also the best performance, but of course you lose the 'designer friendly' templates. I think it's important to consider the maintainability aspect, not only raw performance (until you really need it, and even then, caching is more helpful).

有关小东东(日期或名称格式等)我会使用助手,因为HTML通常是一个班的跨度,为更复杂的东西,我会使用的显示模板。

For small stuff (date or name formatting etc) i'd use helpers, since the html is usually a span with a class, for more complex stuff I'd use the display templates.

这篇关于VS的RenderAction性能的RenderPartial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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