Skip to content

[Bug]: ReactiveProperty very slow with many subscriber #3935

Open
@DevEngineReq

Description

@DevEngineReq

Describe the bug 🐞

Recently we moved the ReactiveProperty from Reactive.Bindings.ReactiveProperty to ReactiveUI.ReactiveProperty.
Now we encountered massiv performance problems for the following use case.

If you subscribe a ReactiveProperty very often, the application will freeze. It is very performace intensiv.
With Reactive.Bindings.ReactiveProperty it was not a problem.

Example

public class BasicComparisonViewModel
{

    private readonly SourceCache<BasicViewModel, int> cache = new(static x => x.Id);

    // ReactiveUI => slow
    public ReactiveProperty<int> Property => new (42);

    // System.Reactive => fast
    //public Reactive.Bindings.ReactiveProperty<int> Property => new Reactive.Bindings.ReactiveProperty<int>(42);

    public BasicComparisonViewModel()
    {
        this.cache.Edit(x =>
        {
            for(var i = 0; i < 3000; i++)
            {
                x.AddOrUpdate(new BasicViewModel(i, this));
            }
        });
    }
}

internal class BasicViewModel
{
    public int Id { get; }

    public BasicViewModel(int id, BasicComparisonViewModel vm)
    {
        this.Id = id;

        vm.Property.Subscribe();
    }
}

Our measurements
Reactive.Bindings.ReactiveProperty: ~3ms
ReactiveUI.ReactiveProperty: ∞

Step to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

This should happen...

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions