问题描述:

Why is ReactiveList with ChangeTrackingEnabled slow when I Clear inside SuppressChangeNotifications?

With 10,000 entries it takes about 2 seconds for the Clear method to return.

Shouldn't SuppressChangeNotifications bypass the change tracking code?

Or how can I improve the performance here?

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

using (_personList.SuppressChangeNotifications())

{

_personList.Clear();

}

Thanks a lot.

网友答案:

Change tracking code is bypassed, but still ReactiveList needs to cleanup its internal stuff when you clear the list. And the method used to do so is extremely inefficient ( O(n2) ), as detailed in this SO answer.

The Clear implementation with change tracking enabled can definitely be improved, I'll send a PR to RxUI if I get the chance.

E.g. replacing this code by foreach (var foo in _propertyChangeWatchers.Values.ToList()) foo.Release(); makes the Clear immediate, w/o altering the behavior.

EDIT :

You can work around this performance issue by writing instead:

using (_personList.SuppressChangeNotifications())
    _personList.RemoveRange(0, _personList.Count);
相关阅读:
Top