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

Specialized observables for transitions #5953

Merged
merged 10 commits into from
May 30, 2021

Conversation

MarchingCube
Copy link
Collaborator

@MarchingCube MarchingCube commented May 19, 2021

What does the pull request do?

Reworked transitions to utilize custom observables, this eliminates several allocations and speeds up transitions,

Method Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
OldTransition 2.349 us 0.0211 us 0.0176 us 1.00 0.0687 - - 296 B
NewTransition 1.729 us 0.0135 us 0.0120 us 0.74 0.0401 - - 168 B

Stack traces also look more sane (left = old, right = new). First one is for initial application of the transition, second one is for timer tick. I think timer tick can be cleaned up even further by replacing Rx setup with our specialized lightweight observable (since there are no threading concerns).

image

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@MarchingCube
Copy link
Collaborator Author

cc: @maxkatz6 Since you were changing that code lately as well.

@MarchingCube
Copy link
Collaborator Author

By getting rid of refcounting in ClockBase stack traces for ticking transitions look quite decent:
image


private TimeSpan? _previousTime;
private TimeSpan _internalTime;

protected ClockBase()
{
_observable = new ClockObservable();
_connectedObservable = _observable.Publish().RefCount();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apart from adding 6 layers of indirection this was not doing anything useful. This observable does not initialize any resources when subscribed. I guess it was remnant of times where subscribing to clock was creating an actual timer.

@MarchingCube
Copy link
Collaborator Author

MarchingCube commented May 23, 2021

Method FrameCount Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
OldTransition 10 474.9 ns 2.20 ns 1.95 ns 1.00 0.0648 - - 272 B
NewTransition 10 266.7 ns 1.71 ns 1.60 ns 0.56 0.0381 - - 160 B
OldTransition 100 2,111.6 ns 8.11 ns 7.19 ns 1.00 0.0648 - - 272 B
NewTransition 100 1,683.6 ns 6.55 ns 6.12 ns 0.80 0.0381 - - 160 B

Updated benchmarks after fixing invalid time easing.

@MarchingCube
Copy link
Collaborator Author

@maxkatz6 I've discussed new API surface with @grokys - I think we are fine with adding a few classes to improve perf and maintainability here. We could experiment a bit after merging core libraries, but also by that time we might also rework transitions a bit to be less reliant on observables.

@MarchingCube MarchingCube marked this pull request as ready for review May 23, 2021 23:55
@MarchingCube MarchingCube requested a review from grokys May 23, 2021 23:57
@MarchingCube MarchingCube changed the title WIP: Specialized observables for transitions Specialized observables for transitions May 29, 2021
@maxkatz6
Copy link
Member

@MarchingCube I think, it can be backported to 0.10.x ?

@MarchingCube
Copy link
Collaborator Author

@maxkatz6 Yeah, in the current form it breaks no APIs and improves perf/readability of transition code.

@MarchingCube MarchingCube merged commit 02aad98 into AvaloniaUI:master May 30, 2021
@MarchingCube MarchingCube deleted the refactor-transitions branch May 30, 2021 18:57
danwalmsley pushed a commit that referenced this pull request Jun 4, 2021
Specialized observables for transitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants