AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.05k stars 2.25k forks source link

Severe performance degradation on Linux when looking up fonts family from preview5 -> 6 #10845

Open aldelaro5 opened 1 year ago

aldelaro5 commented 1 year ago

Describe the bug There has been 2 cases where I could measure significant performance degradation on Linux which seemingly involves font family lookup in Skia. Those 2 cases include this one which I documented how I measured this degradation when I tried to upgrade AvaloniaEdit here: https://github.com/AvaloniaUI/AvaloniaEdit/pull/318 We can see the hot path seems to be about the method MatchFamily from SkiaSharp. I am posting this issue because I just ran into a second completely different case with the exact same measurements and it involves the Semi.Avalonia's theme.

To Reproduce Simply clone the https://github.com/irihitech/Semi.Avalonia repos and run the desktop demo on linux using the v0.1.0-preview6.1 tag. You should notice a particularly long startup time. Now, checkout the tag v0.1.0-preview5.4 which should have avalonia downgraded to preview5. Build the desktop demo app and when ran, it should have an acceptable startup time, much quicker.

Here are my measurements I gathered using Rider's profiling tool in timeline mode (both measurements were done in release configuration):

v0.1.0-preview5.4 (this looks normal, using the app also yields good performance here) Screenshot from 2023-03-29 21-40-33

v0.1.0-preview6.1 which uses preview6 (This has a significant hot spot, using the app leads to long lag time particularly on startup and switching tabs, sometime even stalling for seconds with the UI thread seemingly blocked) Screenshot from 2023-03-29 21-46-04

Expected behavior The performance to match or exceed preview5.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context I am unable to measure or notice a performance degradation using a Windows vm. This implies the issue is likely Linux specific.

cc: @rabbitism @Gillibald

rabbitism commented 1 year ago

Thanks for testing. I don't have a Linux machine to test the performance, so I didn't notice the difference. There was an update of FontManager in preview6, however I'm not touching it at all. Maybe @Gillibald could help to identify if anything is not correctly used.

SKProCH commented 1 year ago

Also, it seems like dev tools work much slower in preview 6 on Linux. I think this is related to this issue.

Washi1337 commented 1 year ago

I can confirm this is the case. In a project of mine where I switched from preview5 to preview6, I can see very similar measurements with the same hotspot in the MatchFamily function. In particular, I noticed the degradation seems to be the worst when a font family is not installed and the rendering engine defaults to a fallback font. More specifically for my case, I had "Consolas" set to some of my controls which I did not have installed on my Linux machine, and resizing the parent window caused severe lag spikes. Changing it to a font I had installed significantly improved performance again.

Kernel: 5.10.174-1-MANJARO (64-bit) DM: KDE Plasma 5.26.5

Gillibald commented 1 year ago

Please try out #10857 once the build has finished

aldelaro5 commented 1 year ago

Please try out #10857 once the build has finished

Tried to use the avalonia-all feed with the build on semi.avalonia's repos and got this on boot (in Main)

System.TypeLoadException: Method 'TryMatchCharacter' in type 'Avalonia.Skia.FontManagerImpl' from assembly 'Avalonia.Skia, Version=11.0.0.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b' does not have an implementation.
   at Avalonia.Skia.SkiaPlatform.Initialize(SkiaOptions options)
   at Avalonia.SkiaApplicationExtensions.<>c.<UseSkia>b__0_0() in /_/src/Skia/Avalonia.Skia/SkiaApplicationExtensions.cs:line 19
   at Avalonia.AppBuilder.Setup() in /_/src/Avalonia.Controls/AppBuilder.cs:line 256
   at Avalonia.AppBuilder.SetupWithLifetime(IApplicationLifetime lifetime) in /_/src/Avalonia.Controls/AppBuilder.cs:line 162
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 214
   at Semi.Avalonia.Demo.Desktop.Program.Main(String[] args) in /home/aldelaro5/RiderProjects/Semi.Avalonia/demo/Semi.Avalonia.Demo.Desktop/Program.cs:line 14
timunie commented 1 year ago

@aldelaro5 most likely you cannot mix different Avalonia versions. So if Semi.Avalonia has a different Avalonia version used, this will not be possible (consumed as a nuget). You can still clone the source of Semi.Avalonia and add it as a project reference. Some adjustments may be needed.

aldelaro5 commented 1 year ago

@Gillibald turns out @timunie was right, but I tested and unfortunately it does not solve the issue. I know I must have used a more recent version because I am seeing dispatcher name changes in the stacktrace above: Screenshot from 2023-03-31 18-37-04