当我在SuppressChangeNotifications中清除时,为什么ReactiveList与ChangeTrackingEnabled会变慢?

时间:2015-08-18 15:52:18

标签: reactiveui

当我在SuppressChangeNotifications中清除时,为什么ReactiveList与ChangeTrackingEnabled会变慢?

使用10,000个条目,Clear方法返回大约需要2秒钟。

不应该禁止更改通知绕过更改跟踪代码吗?

或者我如何在这里改善表现呢?

ReactiveList<Person> _personList = new ReactiveList<Person> { ChangeTrackingEnabled = true };


            using (_personList.SuppressChangeNotifications())
            {
                _personList.Clear();
            }

非常感谢。

1 个答案:

答案 0 :(得分:2)

绕过更改跟踪代码,但在清除列表时,ReactiveList仍需要清除其内部内容。而method used这样做的效率非常低(O(n2)),详见this SO answer

启用更改跟踪的Clear实现肯定可以改进,如果有机会我会向RxUI发送PR。

E.g。将代码替换为foreach (var foo in _propertyChangeWatchers.Values.ToList()) foo.Release();会使Clear立即生效,而不会改变行为。

编辑

您可以通过编写代码来解决此性能问题:

using (_personList.SuppressChangeNotifications())
    _personList.RemoveRange(0, _personList.Count);