Skip to content

SP5: frequent typeface lookups result in poor performance on Linux #2833

@taya92413

Description

@taya92413

Bug Report

Issue:
Very poor performance, only 10-20FPS
Referring to #2419 could solve the performance issue, but I am not sure about the problems encountered on .NET Framework, so it was not ultimately resolved.

#2419 method:
Modify source code
Path: ScottPlot-main\src\ScottPlot5\ScottPlot5\Extensions\SkiaSharpExtensions.cs
Add a static SKTypeface to avoid searching for SKTypeface every time rendering occurs.
Finally build the .dll

    //Add
    private static SKTypeface? _typeface = null;

    public static void ApplyToPaint(this FontStyle fontStyle, SKPaint paint)
    {
        SKFontStyleWeight weight = fontStyle.Bold ? SKFontStyleWeight.Bold : SKFontStyleWeight.Normal;
        SKFontStyleSlant slant = fontStyle.Italic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright;
        SKFontStyleWidth width = SKFontStyleWidth.Normal;
        SKFontStyle skfs = new(weight, width, slant);

        //SKTypeface typeface = SKTypeface.FromFamilyName(fontStyle.Name, skfs);

        //Add choose one of the two, they are the same
        SKTypeface typeface = _typeface ?? (_typeface = SKTypeface.FromFamilyName(fontStyle.Name, skfs));
        //SKTypeface typeface = (_typeface == null) ? _typeface = SKTypeface.FromFamilyName(fontStyle.Name, skfs) : _typeface;


        paint.Typeface = typeface;
        paint.TextSize = fontStyle.Size;
        paint.Color = fontStyle.Color.ToSKColor();
        paint.IsAntialias = fontStyle.AntiAlias;
    }

Low performance picture:
螢幕擷取畫面 2023-08-04 095502

Reproducing:
a code sample
Xaml:

<ScottPlot:AvaPlot Name="AvaPlot1" />

C#:

   double[] dataX = { 1, 2, 3, 4, 5 };
   double[] dataY = { 1, 4, 9, 16, 25 };

   AvaPlot avaPlot1 = this.Find<AvaPlot>("AvaPlot1");
   avaPlot1.Plot.Add.Scatter(dataX, dataY);
   avaPlot1.Refresh();

System Details

  • ScottPlot Version: 5.0.6 beta
  • Operating System: Ubuntu20.04、Ubuntu22.04、WSL
  • Application Type: Avalonia11.0.2
  • .NET Version: .NET 6.0、.NET 7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGunexpected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions