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

Use custom Rx classes #1690

Merged
merged 20 commits into from Jun 25, 2018

Conversation

Projects
None yet
5 participants
@grokys
Member

grokys commented Jun 23, 2018

A large proportion of our memory usage is taken up by Rx operators. The standard rx operators carry out a lot of allocations for two reasons:

  1. To be thread-safe
  2. Because they are general purpose and need to be chained together

This PR introduces a new LightweightObservableBase<T> class which takes advantage of the fact that our UI is single-threaded, and is used to build custom rx classes so that we no longer need to chain standard rx operators.

Memory usage

Memory usage was measured via the VS2017 diagnostic tools by running ControlCatalog in Release mode, opening all pages and then taking a memory snapshot:

master:

Objects Heap Size (KB)
3,416,050 155,117

This PR:

Objects Heap Size (KB)
1,478,158 79,936

grokys and others added some commits Dec 14, 2017

Implement custom observable for classes.
Use a custom `ClassObserver` for observing changes to a control's classes. This saves shaves off about 15% memory use in ControlCatalog after cyling through all tabs.
Updated ActivatedSubject.
Can be expressed more cleanly given the new `ActivatedObject`.
Make ActivatedValue a custom Observable.
And make `ActivatedObservable` inherit from it.
Added LightweightObservableBase class.
And use it for `ActivatedValue`.
Make AvaloniaPropertyObservable use weak refs.
And remove `WeakPropertyChangedObservable`/`GetWeakObservable`.
Added GetPropertyChangedObservable.
Replaced `GetObservableWithHistory` with `GetPropertyChangedObservable`.

@grokys grokys changed the title from WIP: Use custom Rx classes to Use custom Rx classes Jun 23, 2018

@grokys grokys requested a review from AvaloniaUI/core Jun 23, 2018

@wieslawsoltes

This comment has been minimized.

Contributor

wieslawsoltes commented Jun 23, 2018

LGTM tested with Core2D no issues.

{
if (_observer != null)
{
_observer?.OnNext(value);

This comment has been minimized.

@Karnah

Karnah Jun 23, 2018

Contributor

Check for null call twice?

This comment has been minimized.

@grokys

grokys Jun 23, 2018

Member

Well spotted, thanks!

@wieslawsoltes wieslawsoltes requested review from wieslawsoltes and removed request for wieslawsoltes Jun 24, 2018

@grokys grokys merged commit a9cdfea into master Jun 25, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@grokys grokys deleted the custom-rx branch Jun 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment