2015-08-18 48 views
1

爲什麼當我清除內部SuppressChangeNotifications時,ReactiveList與ChangeTrackingEnabled變慢?當我清除內部SuppressChangeNotifications時,爲什麼ReactiveList與ChangeTrackingEnabled緩慢?

對於10000個條目,Clear方法返回大約需要2秒。

不應該忽略更改跟蹤代碼SuppressChangeNotifications?

或者我該如何提高性能?

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


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

非常感謝。

回答

2

更改跟蹤代碼被繞過,但仍然ReactiveList需要在清除列表時清除其內部的東西。而method used這樣做效率極低(O(n2)),詳見this SO answer

啓用變更跟蹤功能的Clear實施可以絕對得到改善,如果有機會,我會將PR發送給RxUI。

E.g.用foreach (var foo in _propertyChangeWatchers.Values.ToList()) foo.Release();替換此代碼可以立即清除,而不會改變行爲。

編輯

可以解決這個性能問題寫來代替:

using (_personList.SuppressChangeNotifications()) 
    _personList.RemoveRange(0, _personList.Count); 
相關問題