Optimize FontSourceCollection creation from a filesystem directory, reduce allocs #9844
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.
Description
Optimizes building of
FontSourceCollection
and also some work inFontResourceCache
.Path.GetExtension
has a span variant, this prevents string creation just to checkIsSupportedFontExtension
.SupportedExtensions
static array has been removed as it is not needed for anything, anymore.isWindowsFonts
from the previous PR, hence why this is a draft.Directory.GetFiles
, we will use the underlying implementation on .NET Core; theFileSystemEnumerable
.Directory.GetFiles(string)
does (Compatible
).MatchType
to be specified at all (which would be Win32), so it is not.file://
, we will no longer allocate astring[]
of 1.416 files in directory, no matches
351 files in directory, 156 matches
5 files, 1 match
1 file, 1 match
Customer Impact
Decreased allocations, increased performance when initializing from directory.
I've observed about 3-4ms improvement when building from
Fonts
directory (351 files; 156 matches).Regression
No.
Testing
Local build, initializing the collection with folders to look in, testing the functinality via
FontFamily
change.Risk
Low, this is rather simple 1:1 swap. Options for
FileSystemEnumerable
were copied forGetFiles
codepath.Microsoft Reviewers: Open in CodeFlow