Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DevEngineReq opened this issue Nov 21, 2024 · 2 comments
Open

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

DevEngineReq opened this issue Nov 21, 2024 · 2 comments
Labels

Comments

@DevEngineReq
Copy link

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

@ChrisPulman
Copy link
Member

I have done a few tests and it appears that if I include Reactive.Bindings.ReactiveProperty package in the application then indeed the multiple Subscriptions take excessive time to complete, would you be able to test this in two separate projects one with ReactiveUI only and the other with the ReactiveProperty package only, from the tests I have done 3000 subscriptions with ReactiveUI takes around 900 - 1200 ms (framework dependent), this is repeatable over and over from my findings

@DevEngineReq
Copy link
Author

I created a repository with two separate projects

  • ReactivePropertyTest (uses ReactiveProperty.WPF 9.7.0)
  • ReactiveUiTest (uses ReactiveUI.WPF 20.1.63)

Performance Measurements (1000 Subscriber)

Debug Mode
ReactiveProperty = 1ms
ReactiveUI = 18360ms (i do not know why it takes so long while debugging. May you can confirm this behavior)

Normal Start
ReactiveProperty = 1ms
ReactiveUI = 152ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants