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

Behavior subject fixes #94

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Behavior subject fixes #94

merged 2 commits into from
Sep 12, 2024

Conversation

halgari
Copy link
Contributor

@halgari halgari commented Sep 12, 2024

The guts of Rx's BehaviorSubject bottoms out at this

        private void Unsubscribe(IObserver<T> observer)
        {
            lock (_gate)
            {
                if (!_isDisposed)
                {
                    _observers = _observers.Remove(observer);
                }
            }
        }

So yeah, you better hope you don't have a lot of observers on the subject because when they dispose it's a O(n) scan. Replaced the guts of the reactive code in MnemonicDB with R3's variant which are much faster and use array pools, index based removal and a lot of similar features.

Copy link

@Al12rs Al12rs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, @erri120 might know of any gotchas with R3

@halgari halgari merged commit 2e87471 into main Sep 12, 2024
4 checks passed
@halgari halgari deleted the behavior-subject-fixes branch September 12, 2024 16:15
@erri120
Copy link
Member

erri120 commented Sep 13, 2024

Do you have before/after benchmarks?

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

Successfully merging this pull request may close these issues.

3 participants