8000 Optimize FontSourceCollection creation from a filesystem directory, reduce allocs by h3xds1nz · Pull Request #9844 · dotnet/wpf · GitHub
[go: up one dir, main page]

Skip to content

Optimize FontSourceCollection creation from a filesystem directory, reduce allocs #9844

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member
@h3xds1nz h3xds1nz commented Sep 26, 2024

Description

Optimizes building of FontSourceCollection and also some work in FontResourceCache.

  • Path.GetExtension has a span variant, this prevents string creation just to check IsSupportedFontExtension.
  • SupportedExtensions static array has been removed as it is not needed for anything, anymore.
  • I've included the code-path removal for isWindowsFonts from the previous PR, hence why this is a draft.
  • Instead of using Directory.GetFiles, we will use the underlying implementation on .NET Core; the FileSystemEnumerable.
    • I've copied the enumeration options to mimic what Directory.GetFiles(string) does (Compatible).
    • We do not need the MatchType to be specified at all (which would be Win32), so it is not.
    • This will greatly reduce allocations when querying folders with unsupported files, etc.,
  • In case of a single file://, we will no longer allocate a string[] of 1.

416 files in directory, no matches

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Gen1 Allocated [B]
Original 147,452.0 ns 1,774.1 ns 1,659.5 ns 5.6152 4,449 B 1.2207 96320 B
PR__EDIT2 112,287.9 ns 534.4 ns 473.7 ns - 5,824 B - 368 B

351 files in directory, 156 matches

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Gen1 Allocated [B]
Original 170,543.1 ns 973.2 ns 812.6 ns 3.6621 4,989 B 0.2441 62760 B
PR__EDIT2 153,370.2 ns 999.2 ns 885.7 ns 1.4648 4,539 B - 25888 B

5 files, 1 match

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 20,788.0 ns 143.1 ns 126.9 ns 0.0916 5,025 B 1768 B
PR__EDIT2 19,837.8 ns 161.6 ns 151.2 ns 0.0305 6,521 B 600 B

1 file, 1 match

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 19,390.3 ns 177.1 ns 165.7 ns 0.0305 5,031 B 752 B
PR__EDIT2 19,281.6 ns 205.9 ns 189.4 ns 0.0305 6,525 B 600 B

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 for GetFiles codepath.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners September 26, 2024 10:58
@h3xds1nz h3xds1nz marked this pull request as draft September 26, 2024 11:17
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Sep 26, 2024
@h3xds1nz h3xds1nz marked this pull request as ready for review October 7, 2024 16:41
@h3xds1nz
Copy link
Member Author
h3xds1nz commented Oct 7, 2024

Resolved merge conflicts 11

Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Copy link
codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 0% with 92 lines in your changes missing coverage. Please review.

Project coverage is 11.40499%. Comparing base (72af9a5) to head (9be66e3).
Report is 7 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main       #9844         +/-   ##
===================================================
+ Coverage   11.25778%   11.40499%   +0.14720%     
===================================================
  Files           3315        3316          +1     
  Lines         665229      665209         -20     
  Branches       74668       74671          +3     
===================================================
+ Hits           74890       75867        +977     
+ Misses        589035      587938       -1097     
- Partials        1304        1404        +100     
Flag Coverage Δ
Debug 11.40499% <0.00000%> (+0.14720%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@h3xds1nz
Copy link
Member Author
h3xds1nz commented Apr 9, 2025

Rebased and moved things to ctor so that fields can be readonly and broke out the factory to separate file.

However, no code/logic changes have been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions Included in test pass PR metadata: Label to tag PRs, to facilitate with triage Status:Completed Status:Proposed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0