Cache shared platform typeface lookups#503
Merged
Merged
Conversation
This was referenced May 12, 2026
|
Hello. Tested on Svg.Controls.Skia.Avalonia 12.0.0.8 Thanks a lot!!! |
Owner
Author
Thanks for testing, great that its now much faster on Linux. |
|
Great job Wieslaw! Made loading SVG faster on CM4 1GB RAM version! Full HD SVG with icons loaded in about 1-2 seconds! |
This was referenced May 13, 2026
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary: Improve repeated Linux font lookup performance
Related Issue
Fixes #458.
Problem
The issue reports a severe slowdown and apparent freezes when loading many SVG files through
Skia.Controls.Avaloniaon Linux. The remaining investigation pointed at repeated font andglyph fallback work, especially after the draw lock removal and clone/reload fixes had already
reduced other sources of contention.
The expensive paths are repeated across SVG loads:
These lookups are platform-backed and can be especially expensive on Linux font stacks. The
existing instance-local caches help while one
SkiaModel/SkiaSvgAssetLoaderinstance is reused,but they do not help the control-like path that repeatedly constructs loader/model instances while
loading many SVGs.
Changes
SharedTypefaceCache, an internal bounded cache for platform and built-in typeface lookupresults.
DefaultTypefaceProviderFontManagerTypefaceProviderSKFontManager.Defaultfamily/style resolutionSKFontManager.Default.MatchCharacterfallback resultsITypefaceProviderimplementations bypass theshared cache and still run through the existing instance-local provider cache.
re-enter the native font manager for every SVG load.
across separate
SkiaModelinstances.Commit Breakdown
Add shared typeface cacheReuse shared platform font cachesSkiaModel.SkiaSvgAssetLoader.Cover custom provider cache isolationValidation
dotnet format src/Svg.Skia/Svg.Skia.csproj --no-restoredotnet format tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj --no-restoredotnet build Svg.Skia.slnx -c Release --no-restoredotnet test Svg.Skia.slnx -c Release --no-restore --no-builddotnet run --project tests/Svg.Skia.Benchmarks/Svg.Skia.Benchmarks.csproj -c Release --no-restore -- --profile-svg tests/Tests/HitTestText.svg 20Observed benchmark result for
tests/Tests/HitTestText.svg:Control-like source load: mean0.45 msCompile retained scene (parsed doc): mean0.36 msEarlier baseline during investigation showed the same benchmark around:
Control-like source load: mean4.14 msCompile retained scene (parsed doc): mean2.46 msNotes And Risk
investigation, so validation used the repository benchmark harness and existing tests.
for packages such as
Tmds.DBus.Protocol,NuGet.Packaging, andSystem.Security.Cryptography.Xml; these are unrelated to this font cache change.growing without limit.
carry mutable or instance-specific font state.