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

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

Open
aldelaro5 opened this issue Mar 30, 2023 · 7 comments
Labels

Comments

@aldelaro5
Copy link
Contributor

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: AvaloniaUI/AvaloniaEdit#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):

  • OS: Arch Linux 6.2.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 13 Mar 2023 17:02:08 +0000 x86_64 GNU/Linux
  • Version 11.0.0-preview6

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

@aldelaro5 aldelaro5 added the bug label Mar 30, 2023
@aldelaro5 aldelaro5 changed the title Severe performance degradation on Linux when looking up fontsn family from preview5 -> 6 Severe performance degradation on Linux when looking up fonts family from preview5 -> 6 Mar 30, 2023
@rabbitism
Copy link
Contributor

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
Copy link
Contributor

SKProCH commented Mar 30, 2023

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

@Washi1337
Copy link
Contributor

Washi1337 commented Mar 30, 2023

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
Copy link
Contributor

Please try out #10857 once the build has finished

@aldelaro5
Copy link
Contributor Author

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
Copy link
Contributor

timunie commented Mar 31, 2023

@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
Copy link
Contributor Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants