为什么当我在 SuppressChangeNotifications 中清除时,带有 ChangeTrackingEnabled 的 ReactiveList 变慢?
Why is ReactiveList with ChangeTrackingEnabled slow when I Clear inside SuppressChangeNotifications?
当我在 SuppressChangeNotifications 中清除时,为什么带有 ChangeTrackingEnabled 的 ReactiveList 变慢?
对于 10,000 个条目,Clear 方法需要大约 2 秒才能 return。
SuppressChangeNotifications 不应该绕过更改跟踪代码吗?
或者我怎样才能提高这里的性能?
ReactiveList<Person> _personList = new ReactiveList<Person> { ChangeTrackingEnabled = true };
using (_personList.SuppressChangeNotifications())
{
_personList.Clear();
}
非常感谢。
更改跟踪代码被绕过,但 ReactiveList 仍然需要在您清除列表时清理其内部内容。还有 method used to do so is extremely inefficient ( O(n2)
), as detailed in this SO answer.
启用了更改跟踪的 Clear 实现肯定可以改进,如果有机会我会向 RxUI 发送 PR。
例如将此代码替换为 foreach (var foo in _propertyChangeWatchers.Values.ToList()) foo.Release();
会立即清除,w/o 会改变行为。
编辑 :
您可以通过以下方式解决此性能问题:
using (_personList.SuppressChangeNotifications())
_personList.RemoveRange(0, _personList.Count);
当我在 SuppressChangeNotifications 中清除时,为什么带有 ChangeTrackingEnabled 的 ReactiveList 变慢?
对于 10,000 个条目,Clear 方法需要大约 2 秒才能 return。
SuppressChangeNotifications 不应该绕过更改跟踪代码吗?
或者我怎样才能提高这里的性能?
ReactiveList<Person> _personList = new ReactiveList<Person> { ChangeTrackingEnabled = true };
using (_personList.SuppressChangeNotifications())
{
_personList.Clear();
}
非常感谢。
更改跟踪代码被绕过,但 ReactiveList 仍然需要在您清除列表时清理其内部内容。还有 method used to do so is extremely inefficient ( O(n2)
), as detailed in this SO answer.
启用了更改跟踪的 Clear 实现肯定可以改进,如果有机会我会向 RxUI 发送 PR。
例如将此代码替换为 foreach (var foo in _propertyChangeWatchers.Values.ToList()) foo.Release();
会立即清除,w/o 会改变行为。
编辑 :
您可以通过以下方式解决此性能问题:
using (_personList.SuppressChangeNotifications())
_personList.RemoveRange(0, _personList.Count);