Avalonia: Perf/Memory issue tracker

Created on 2 Sep 2019  路  4Comments  路  Source: AvaloniaUI/Avalonia

This is my issue for tracking performance and memory optimization across Avalonia.
Most of my findings come from checking ControlCatalog running on x64 Windows using JetBrains dotMemory.

Renderer:

  • [x] IDeferredRendererLock.TryLock allocates per-frame (https://github.com/AvaloniaUI/Avalonia/pull/2918)
    image
  • [ ] Scene gets cloned completely if any element gets invalidated.
    image
  • [x] Scene.HitTest allocates crazy amounts of iterator blocks
    image
  • [ ] IVisualNode.Children cause enumerator boxing due to access via IReadOnlyList.
    image
  • [x] RenderLoop and DeferredRenderer allocate new lambdas and lambda closure per-frame (Fixed in https://github.com/AvaloniaUI/Avalonia/pull/2960)
    image

Framework:

  • [x] RoutedEvent<T>.AddClassHandler<T> and AvaloniaProperty<T>.AddClassHandler<T> make it very easy (or almost force) to write allocation heavy code. Result below is from moving mouse for few seconds.
    image
  • [x] InputExtensions.GetInputElementsAt cause method group allocation per-call. (Fixed in https://github.com/AvaloniaUI/Avalonia/pull/2927).
  • [x] RoutedEvent is using Delegate.DynamicInvoke which is slow (relies fully on reflection) and allocates a lot of garbage. (Fixed in https://github.com/AvaloniaUI/Avalonia/pull/2931 and https://github.com/AvaloniaUI/Avalonia/pull/2943)
  • [x] Logger API causes each binding and new value to allocate object arrays and box values.
    image
    image

Controls:

Bindings and styling:

  • [ ] Setters and AvaloniaObject.Bind allocate strings for descriptions that most likely will be never seen (in dev tools).
    image
  • [x] Getting StyledProperty default value is always boxing value types. (https://github.com/AvaloniaUI/Avalonia/pull/2935)
    image
  • [x] PriorityBindingEntry is allocating two delegates per instance to subscribe to the binding. Can be avoided completely by using IObserver interface. (https://github.com/AvaloniaUI/Avalonia/pull/2931) image
perf

Most helpful comment

@grokys Hopefully I will get there eventually, right now we still have an order of magnitude worse allocation patterns and I generally pick "easy" things right now that give decent return of investment.

All 4 comments

@ahopper @kekekeks Wrote down my initial findings, I will add more when I find more time. I am already working on certain issues (marked as working on a fix), and I will open PRs slowly as I verify each fix.

Wow!

Another thing that might be worth investigating: LightweightObservableBase always creates a List<IObserver<T>> even if it only has a single observer.

We currently have SingleSubscriberObservableBase but it might be worth merging that with LightweightObservableBase and only creating the list when there are >1 subscribers.

@grokys Hopefully I will get there eventually, right now we still have an order of magnitude worse allocation patterns and I generally pick "easy" things right now that give decent return of investment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

georgiuk picture georgiuk  路  3Comments

maxkatz6 picture maxkatz6  路  3Comments

Suriman picture Suriman  路  3Comments

Urgau picture Urgau  路  3Comments

grokys picture grokys  路  4Comments