ObservableCollection 数据绑定性能
我想知道为什么根据这篇文章和可观察集合显着绑定比 List<> 更快(20 毫秒 vs 1685 毫秒,快 800 倍) WPF 中的集合。 我查看了 ObservableCollection 的内部结构,它使用 List 作为存储集合对象(我使用反射器并在构造函数中看到了这一点)
public Collection()
{
this.items = new List<T>();
}
那么这里发生了什么?
I would like to know why according to this article and observable collection binds significantly faster(20 ms vs 1685ms, that's 800X faster) than a List<> collection in WPF. I looked at the internals of ObservableCollection and it uses a List as it's storage collection object(I used reflector and saw this in the constructor)
public Collection()
{
this.items = new List<T>();
}
So what's going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文章中的比较不是在两个简单的绑定操作之间进行的,这些测量是指将单个项目添加到已经绑定到
List<; 的 WPF
或ListBox
的场景。 T>ObservableCollection
。正如作者所说:
这解释了性能差异。 尽管
ObservableCollection
由List
支持,但它实现了INotifyCollectionChanged
接口,这使得所有额外处理都变得不必要。The comparison in that article isn't between two simple binding operations, those measurements refer to a scenario in which you add a single item to a WPF
ListBox
that is already bound to either aList<T>
or anObservableCollection<T>
.As the author remarks:
This explains the performance difference. Even though
ObservableCollection<T>
is backed by aList<T>
, it implements theINotifyCollectionChanged
interface, which renders all that extra processing unnecessary.