From 606c197d188248d3af2b230cabcede0fbaab7745 Mon Sep 17 00:00:00 2001 From: Vrabbers <25323861+Vrabbers@users.noreply.github.com> Date: Mon, 16 Feb 2026 01:13:17 -0300 Subject: [PATCH 1/2] Cache SKTypeface to avoid UI slowdown on linux with memory view open --- .../Controls/HexEditor.HexViewDrawOperation.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs b/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs index 36bc179f9..06887e537 100644 --- a/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs +++ b/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs @@ -14,6 +14,18 @@ namespace Mesen.Debugger.Controls { public partial class HexEditor { + private static (string Name, SKTypeface Typeface)? s_typefaceCache = null; + + private static SKTypeface GetTypeface(string fontFamily) + { + if (s_typefaceCache == null || s_typefaceCache.Value.Name != fontFamily) { + s_typefaceCache?.Typeface.Dispose(); + s_typefaceCache = (fontFamily, SKTypeface.FromFamilyName(fontFamily)); + } + + return s_typefaceCache.Value.Typeface; + } + class HexViewDrawOperation : ICustomDrawOperation { private HexEditor _he; @@ -125,7 +137,7 @@ private void DrawHexView(SKCanvas canvas, Color color) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(color).ToUInt32()); - SKTypeface typeface = SKTypeface.FromFamilyName(_fontFamily); + SKTypeface typeface = GetTypeface(_fontFamily); SKFont font = new SKFont(typeface, _fontSize); SetFontProperties(font); @@ -232,7 +244,7 @@ private void DrawStringView(SKCanvas canvas, Color color) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(color).ToUInt32()); - SKTypeface typeface = SKTypeface.FromFamilyName(_fontFamily); + SKTypeface typeface = GetTypeface(_fontFamily); SKFont monoFont = new SKFont(typeface, _fontSize); SetFontProperties(monoFont); @@ -473,7 +485,7 @@ public void Render(ImmediateDrawingContext context) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(_headerForeground).ToUInt32()); - SKTypeface typeface = SKTypeface.FromFamilyName(_fontFamily); + SKTypeface typeface = GetTypeface(_fontFamily); SKFont font = new SKFont(typeface, _fontSize); font.Edging = _skiaEdging; font.Subpixel = _skiaSubpixelSmoothing; From fa858faee74217e0dd130d6e1345780d1b7fd1f3 Mon Sep 17 00:00:00 2001 From: Vrabbers <25323861+Vrabbers@users.noreply.github.com> Date: Mon, 16 Feb 2026 01:19:53 -0300 Subject: [PATCH 2/2] Fix formatting --- .../Controls/HexEditor.HexViewDrawOperation.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs b/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs index 06887e537..f0e19f0bd 100644 --- a/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs +++ b/UI/Debugger/Controls/HexEditor.HexViewDrawOperation.cs @@ -14,11 +14,11 @@ namespace Mesen.Debugger.Controls { public partial class HexEditor { - private static (string Name, SKTypeface Typeface)? s_typefaceCache = null; + private static (string Name, SKTypeface Typeface)? s_typefaceCache = null; - private static SKTypeface GetTypeface(string fontFamily) + private static SKTypeface GetCachedTypeface(string fontFamily) { - if (s_typefaceCache == null || s_typefaceCache.Value.Name != fontFamily) { + if(s_typefaceCache == null || s_typefaceCache.Value.Name != fontFamily) { s_typefaceCache?.Typeface.Dispose(); s_typefaceCache = (fontFamily, SKTypeface.FromFamilyName(fontFamily)); } @@ -137,7 +137,7 @@ private void DrawHexView(SKCanvas canvas, Color color) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(color).ToUInt32()); - SKTypeface typeface = GetTypeface(_fontFamily); + SKTypeface typeface = GetCachedTypeface(_fontFamily); SKFont font = new SKFont(typeface, _fontSize); SetFontProperties(font); @@ -244,7 +244,7 @@ private void DrawStringView(SKCanvas canvas, Color color) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(color).ToUInt32()); - SKTypeface typeface = GetTypeface(_fontFamily); + SKTypeface typeface = GetCachedTypeface(_fontFamily); SKFont monoFont = new SKFont(typeface, _fontSize); SetFontProperties(monoFont); @@ -485,7 +485,7 @@ public void Render(ImmediateDrawingContext context) SKPaint paint = new SKPaint(); paint.Color = new SKColor(ColorHelper.GetColor(_headerForeground).ToUInt32()); - SKTypeface typeface = GetTypeface(_fontFamily); + SKTypeface typeface = GetCachedTypeface(_fontFamily); SKFont font = new SKFont(typeface, _fontSize); font.Edging = _skiaEdging; font.Subpixel = _skiaSubpixelSmoothing;