Skip to content

ReactiveList creation performance #1276

@megafinz

Description

@megafinz

Do you want to request a feature or report a bug?

Neither, I guess it would be an improvement request.

What is the current behavior?

Currently ReactiveList<T> is quite expensive to create in comparison to ObservableCollection<T> which is a problem in case you have thousands of them created at the same time.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

        var count = 20000;
        var rls = new List<ReactiveList<string>>();
        var ocs = new List<ObservableCollection<string>>();

        var sw = Stopwatch.StartNew();
        for (var i = 0; i < count; ++i)
        {
            rls.Add(new ReactiveList<string>());
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds);

        sw.Restart();
        for (var i = 0; i < count; ++i)
        {
            ocs.Add(new ObservableCollection<string>());
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds);

On my machine it takes about 1200ms to create ReactiveLists and 25ms to create ObservableCollections (that's almost 50 times longer).

What is the expected behavior?

It would be nice if creation time of ReactiveLists would be comparable to that of ObservableCollections.

What is the motivation / use case for changing the behavior?

I'd like to lessen the performance impact of creating ReactiveLists in my code. Currently it takes around 20% of overall execution time of that specific code to create them.

Which versions of ReactiveUI, and which platform / OS are affected by this issue? Did this work in previous versions of ReativeUI? Please also test with the latest stable and snapshot (http://docs.reactiveui.net/en/contributing/snapshot/index.html) versions.

We're using ReactiveUI 7.1.0 on Windows for WPF desktop application development.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Performance profiling shows that the bottleneck sits in the ReactiveList.setupRx method and more specifically in this place (Observable.Subscribe, Profiler Screenshot):

CountChanging.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanging("Count"));
CountChanged.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("Count"));
IsEmptyChanged.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("IsEmpty"));
Changing.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanging("Item[]"));
Changed.Where(_ => this.areChangeNotificationsEnabled()).Subscribe(_ => this.RaisePropertyChanged("Item[]"));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions