Logo van Avalonia Performance

Avalonia Performance

Community
linuxdevel
avalonia-performance

Use when diagnosing or improving Avalonia performance — slow scrolling or large lists (virtualization, TableView), FPS/layout/render profiling with DevTools and RendererDiagnostics overlays, compiled vs reflection bindings, image decode size, visual-tree depth, startup time and size (ReadyToRun, trimming, NativeAOT), and memory leaks (event handlers, DataContext, images).

Overzicht

Uitgeverlinuxdevel
RepositoryAvalonia-skills
Skillnaamavalonia-performance
Sterren
50
Forks
4
Meegeleverde bestanden
Alleen instructies
LicentieMIT
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Compleet zonder extra bestanden

    Alles wat het model nodig heeft, staat in de instructies — geen extra bestanden om te synchroniseren.

  • Open source

    Gepubliceerd door linuxdevel op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Avalonia Performance in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/linuxdevel/Avalonia-skills/tree/main/skills/avalonia/avalonia-performance
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/linuxdevel/Avalonia-skills.git /tmp/Avalonia-skills
mkdir -p .claude/skills
cp -r /tmp/Avalonia-skills/skills/avalonia/avalonia-performance .claude/skills/avalonia-performance
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Avalonia Performance in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Avalonia Performance automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Avalonia Performance niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

Avalonia Performance & Diagnostics

Version labels follow avalonia-versions: (12.0+), (12.1+), (11.x), no label = 11.3/12.0/12.1. For publish steps (RIDs, single file, installers) see avalonia-deployment; this skill covers only the performance-relevant flags.

Workflow

  1. Measure first: overlay FPS/layout/render graphs, then DevTools visual tree, then dotnet-counters/dotnet-trace.
  2. Fix the biggest cost: usually (a) non-virtualized big list, (b) reflection bindings, (c) full-size image decode, (d) deep/huge visual tree, (e) work on the UI thread.
  3. Re-measure in Release (dotnet run -c Release); Debug builds and an attached debugger distort results.

Diagnosing

DevTools

PackageCall
(12.0+)AvaloniaUI.DiagnosticsSupport (+ AvaloniaUI.DeveloperTools global tool avdt, Avalonia Plus tooling)this.AttachDeveloperTools(); in Application.Initialize()
(11.x)Avalonia.Diagnosticsthis.AttachDevTools(); (or window.AttachDevTools())
csharp
public override void Initialize()
{
    AvaloniaXamlLoader.Load(this);
#if DEBUG
    this.AttachDeveloperTools();   // (12.0+) — AppBuilder equivalent: .WithDeveloperTools()
#endif
}

Avalonia.Diagnostics has no 12.x release; never reference both. Options (DeveloperToolsOptions): ConnectOnStartup, Runner, Protocol (HTTP default port 29414, or named pipes), AutoConnectFromDesignMode, DiagnosticLogger. Docs: https://docs.avaloniaui.net/tools/developer-tools/installation

Renderer overlays (all versions)

TopLevel.RendererDiagnostics.DebugOverlays is a [Flags] enum RendererDebugOverlays (namespace Avalonia.Rendering):

FlagShows
Fpsframes per second
DirtyRectsinvalidated rectangles per frame
LayoutTimeGraphrecent layout pass times
RenderTimeGraphrecent render times
csharp
var top = TopLevel.GetTopLevel(this)!;
top.RendererDiagnostics.DebugOverlays =
    RendererDebugOverlays.Fps | RendererDebugOverlays.LayoutTimeGraph | RendererDebugOverlays.RenderTimeGraph;
// toggle off: RendererDebugOverlays.None

How to read: large dirty rects every frame on a static screen means something is animating or invalidating continuously; tall layout graph means layout thrash (see below); tall render graph means heavy drawing (shadows, big images, effects).

.NET tooling (run against the app process)

sh
dotnet-counters monitor --process-id <pid> System.Runtime        # GC heap, alloc rate, gen0/1/2 counts, threadpool
dotnet-trace collect --process-id <pid> --profile cpu-sampling   # open .nettrace in PerfView / VS / Speedscope
dotnet-gcdump collect --process-id <pid>                         # heap snapshot to find leaked controls/VMs

Install these tools yourself from nuget.org (dotnet tool install --global dotnet-counters); verify package ids before installing. Rising gen2 heap after closing windows/views means a leak (see Memory).

UI Performance

Virtualization

ControlVirtualizes by default?
ListBox, ComboBox dropdown, TreeView-style items hostsYes (VirtualizingStackPanel)
ItemsControlNo; ItemsPanel defaults to StackPanel
TableView (12.1+)Yes, recycles rows and cells
DataGridYes (rows); maintenance mode in 12.1, prefer TableView/TreeDataGrid
ItemsRepeaterRetired, not supported as of 12. Migrate to ItemsControl/ListBox
xml
<!-- ItemsControl with virtualization -->
<ScrollViewer>
  <ItemsControl ItemsSource="{Binding Items}">
    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate><VirtualizingStackPanel/></ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
  </ItemsControl>
</ScrollViewer>
<!-- Simpler: use ListBox; style it if you do not want selection visuals -->

VirtualizingStackPanel members: Orientation, CacheLength (extra space realized above/below viewport; raising it trades memory for smoother scrolling), FirstRealizedIndex / LastRealizedIndex (-1 when nothing realized; handy in a diagnostic to confirm virtualization is active).

What breaks virtualization (the panel gets unlimited space, realizes every item):

  • Putting the list inside an unconstrained-height parent: StackPanel, ScrollViewer with VerticalScrollBarVisibility="Auto" wrapping a ListBox, or Grid row with Height="Auto". Give the list a bounded height (* row, DockPanel fill) and let the list own its scrolling.
  • Nesting a ListBox inside a ScrollViewer just to "scroll the page".
  • Replacing ItemsPanel with a non-virtualizing panel (StackPanel, WrapPanel, UniformGrid).
  • Variable-size, very heavy ItemTemplates (virtualization works, but each realization is expensive; flatten the template).
  • Realizing everything in code (ItemsPanelRoot.Children loops, ContainerFromIndex over the whole range).

Also: bind ItemsSource to an ObservableCollection<T> and mutate incrementally; replacing the whole collection reference rebuilds every container. For bulk loads, build the list then assign once.

Bindings

Cost
Compiled (x:DataType set)fastest, build-time checked, trim/AOT safe. Default in 12.0+
{ReflectionBinding} / (11.x) default {Binding}reflection at runtime, slower, trimmer-unsafe
  • (12.0+) {Binding} without x:DataType fails to compile; set x:DataType on the view root and on DataTemplates.
  • (11.x) Opt in project-wide: <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>, or per-file x:CompileBindings="True".
  • C# (12.0+): CompiledBinding.Create((Item i) => i.Value) instead of new Binding(...).
  • Avoid converters that allocate per update; cache results. Prefer MultiBinding only when necessary.
  • Do not raise PropertyChanged in tight loops; batch updates then notify once, and never update bound VM properties from background threads without Dispatcher.UIThread.Post.

Visual tree, layout, rendering

  • Fewer elements: replace nested Border > Grid > StackPanel chains with a single Grid/Border; use TextBlock instead of Label/ContentControl for plain text; avoid wrapper ContentControls in item templates.
  • Layout invalidation: changing Width/Height/Margin/Text of a control invalidates measure/arrange up the tree. Animate RenderTransform/Opacity instead of size/margin. Fix sizes where possible so a change does not propagate; avoid Auto sizing cycles in Grid (SharedSizeGroup across many items is costly).
  • Hidden controls: IsVisible="False" removes a subtree from layout/render; Opacity="0" does not. (12.0+) style-triggered animations on hidden controls pause (override with Animation.PlaybackBehavior="Always").
  • Expensive effects: BoxShadow (especially large blur on many items), OpacityMask, Effect (blur/drop-shadow) and clipping are costly per frame. Use sparingly on list items; prefer a flat border or one shadow on the container. Verify with the RenderTimeGraph overlay.
  • Cache immutable resources: share one SolidColorBrush/Geometry/Pen (static field or StaticResource) rather than allocating in Render/converters. Freeze via ToImmutable() for IBrush created in code.
  • Custom controls: draw in Render(DrawingContext), call InvalidateVisual() only when state changes, and use AffectsRender<T>(...)/AffectsMeasure<T>(...) for styled properties instead of manual invalidation.
  • Heavy work off the UI thread: await Task.Run(...) then marshal the result with Dispatcher.UIThread.InvokeAsync.

Images

Decode at display size, not source size:

csharp
await using var s = await file.OpenReadAsync();
var thumb = Bitmap.DecodeToWidth(s, 160, BitmapInterpolationMode.MediumQuality); // keeps aspect ratio
// Bitmap.DecodeToHeight(stream, height, mode) also exists
  • A 4000x3000 photo shown in a 160px thumbnail costs ~48 MB decoded vs ~1 MB at thumbnail size. Decode thumbnails on a background thread.
  • Dispose Bitmaps you own (IDisposable) when views go away; cache with a bounded LRU keyed by path+size, not an unbounded dictionary.
  • Image.Stretch/RenderOptions.BitmapInterpolationMode set on the control control downscaling quality (lower quality is cheaper).
  • (12.1+) creating a bitmap directly from pixels is several times faster.

12.x Rendering Facts (no code change needed)

VersionChange
12.0Large FPS improvements on complex scenes; Skia is the only desktop renderer (Direct2D1 removed; it lacked parity)
12.1Hit-testing reworked for containers with many visuals (up to several hundredfold in extreme cases)
12.1Compositor render-data serialization rewritten: far fewer allocations, fewer GC pauses
12.1Stencil buffers on by default (more HW-accelerated clipping); multiple dirty-rect clipping off by default (helps discrete GPUs)
12.1X11 and Windows (render modes other than WinUIComposition) render at monitor refresh rate (>60 FPS); GPU/CPU use may rise vs 12.0
12.1Windows GPU surface creation changed when transparency not needed: lower GPU use on integrated graphics

Source: https://avaloniaui.net/blog/release-12-1. If 12.1 regresses a specific GPU/driver, file an issue with the overlays enabled and a repro rather than pinning workarounds.

Startup & Size

xml
<PropertyGroup>
  <!-- Startup: precompiled native code next to IL; needs a RID; assemblies grow 2-3x -->
  <PublishReadyToRun>true</PublishReadyToRun>
  <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  <SelfContained>true</SelfContained>

  <!-- Size: trimming (self-contained publish) -->
  <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
TechniqueNotes
ReadyToRun-p:PublishReadyToRun=true with -r <RID>. Cuts JIT time at startup and first use; tiered compilation later re-JITs hot methods. Exclude assemblies with <PublishReadyToRunExclude Include="X.dll"/>. Small apps see little gain
TrimmingNeeds compiled bindings; reflection bindings, runtime XAML loading, Activator/Type.GetType and reflection-based serializers/DI get trimmed away. Fix trim warnings, do not suppress them
Libraries<IsAotCompatible>true</IsAotCompatible> implies IsTrimmable + trim/AOT analyzers (net8.0+ target needed for analysis)
Reflection-based library breaksRoot it: <TrimmerRootAssembly Include="YourAssembly" /> next to its ProjectReference
NativeAOTPublishAot in the executable project only; IsAotCompatible in all libraries. Avalonia documents desktop NativeAOT (Windows/Linux/macOS)

NativeAOT per Avalonia docs (https://docs.avaloniaui.net/docs/deployment/native-aot):

xml
<PropertyGroup>
  <PublishAot>true</PublishAot>            <!-- main exe project only -->
  <IsAotCompatible>true</IsAotCompatible>  <!-- every project/library -->
  <!-- Only needed before Avalonia 12.0 (accessibility APIs): -->
  <BuiltInComInteropSupport>false</BuiltInComInteropSupport>
</PropertyGroup>

dotnet publish -r win-x64 -c Release

Caveats (Avalonia + .NET docs): no runtime loading of XAML or Assembly.LoadFile, no Reflection.Emit; dynamically created controls need trimmer settings; some third-party controls are not AOT-compatible; design-time preview is limited; System.Linq.Expressions run interpreted; Linux binaries only run on same-or-newer distro; all generic struct instantiations are pre-generated (size). Prefer x:CompileBindings/default compiled bindings, AvaloniaResource assets, compile-time DI registration (no reflection service location). Official NativeWebView (12.0+, Avalonia.Controls.WebView) is intended to be AOT-friendly; test your publish to confirm.

Trade-off: NativeAOT gives fastest startup and no JIT, but ReadyToRun + trimming is the lower-risk path for apps that use reflection-heavy libraries (reactive frameworks, serializers, plugin loading).

Memory

  • Event handlers: source.Event += handler keeps the subscriber alive for the source's lifetime. Unsubscribe in OnDetachedFromVisualTree/Unloaded, or when the VM is disposed. Static/long-lived sources (singletons, services, Application, INotifyCollectionChanged collections) are the usual culprits.
  • Lambdas and anonymous handlers cannot be unsubscribed unless stored; use named methods or keep the delegate.
  • Weak subscriptions: for a long-lived publisher and short-lived subscriber, use a weak-event pattern (WeakReference handler wrapper, or a messenger with weak references such as CommunityToolkit.Mvvm WeakReferenceMessenger). Verify the library API before use.
  • DataContext leaks: a VM that holds references to views (or to Window) and is cached by a service keeps whole visual trees alive. Keep VMs view-agnostic; dispose/clear a view's DataContext when its VM is replaced; unsubscribe VMs from services in IDisposable.Dispose.
  • Observable subscriptions (Observable.Subscribe, GetObservable(...)): keep the IDisposable, dispose when the owner goes away (CompositeDisposable).
  • Images/streams: dispose bitmaps and streams; bound caches (see Images).
  • Find leaks: dotnet-gcdump, take snapshot after opening/closing a view 10 times; instance count of the view/VM type should not grow.
  • Timers: DispatcherTimer and Task.Delay loops must be stopped when the control detaches; (12.0+) create timers on the UI thread (they use the current dispatcher).

Common Mistakes

  • Measuring in Debug or with a debugger attached, then optimizing noise.
  • ListBox/ItemsControl inside ScrollViewer or StackPanel: virtualization silently off; thousands of containers realized.
  • Using ItemsControl for a large list without a virtualizing ItemsPanel; or still using ItemsRepeater in a 12.x project (retired).
  • Reflection {Binding} in an 11.x project that could use compiled bindings; (12.0+) using {ReflectionBinding} everywhere "to make it compile" instead of adding x:DataType.
  • Loading full-resolution images for thumbnails; not disposing bitmaps.
  • BoxShadow/blur on every list item, large OpacityMasks, Opacity="0" instead of IsVisible="False".
  • Animating Width/Height/Margin (layout every frame) instead of RenderTransform/Opacity.
  • Calling AttachDevTools() in a 12.x project or referencing Avalonia.Diagnostics (no 12.x package); leaving DevTools enabled in Release (guard with #if DEBUG).
  • Enabling PublishTrimmed/PublishAot and ignoring trim warnings; runtime crashes appear only after publish. Test the published binary, not dotnet run.
  • Event subscriptions to singletons never removed; VMs holding view references.
  • Assuming 60 FPS pacing in 12.1 on X11/Windows: animation must be time-based; CPU/GPU use can rise on high-refresh monitors.

Sources

Veelgestelde vragen

Wat doet de AI-skill Avalonia Performance?

Use when diagnosing or improving Avalonia performance — slow scrolling or large lists (virtualization, TableView), FPS/layout/render profiling with DevTools and RendererDiagnostics overlays, compiled vs reflection bindings, image decode size, visual-tree depth, startup time and size (ReadyToRun, trimming, NativeAOT), and memory leaks (event handlers, DataContext, images).

Waarom Avalonia Performance gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Avalonia Performance bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Avalonia Performance in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/linuxdevel/Avalonia-skills/tree/main/skills/avalonia/avalonia-performance. TypingMind leest het bestand SKILL.md en installeert het als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Avalonia Performance gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Avalonia Performance gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Avalonia Performance ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Avalonia Performance gratis?

Ja. Deze skill is door linuxdevel op GitHub gepubliceerd onder de licentie MIT. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇