Skip to content

Optimize lookups in FontEmbeddingManager, use HashSet over Dictionary#10002

Open
h3xds1nz wants to merge 5 commits intodotnet:mainfrom
h3xds1nz:font-embed-lookups
Open

Optimize lookups in FontEmbeddingManager, use HashSet over Dictionary#10002
h3xds1nz wants to merge 5 commits intodotnet:mainfrom
h3xds1nz:font-embed-lookups

Conversation

@h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Oct 26, 2024

Description

Optimizes methods in FontEmbeddingManager, using HashSet<ushort> over Dictionary<ushort, bool> since the bool is useless and as the comment says, it was always the plan anyways.

  • GetUsedGlyphs throws KeyNotFoundException over ArgumentException but that bug was already present.
    • I'll log an issue for this later.

3 Different faces, 9 Glyph Runs

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 1,344.4 ns 13.79 ns 12.23 ns 0.1507 1,066 B 2544 B
PR_EDIT 850.7 ns 11.54 ns 10.23 ns 0.1297 1,577 B 2184 B
Benchmark data source
yield return new List<GlyphRun>() { giveme("Consolas", "hello"), giveme("Arial", "hannah"), giveme("Consolas", "test"),
                                    giveme("Arial", "hello"), giveme("Consolas", "hannah"), giveme("Arial", "test"),
                                    giveme("Times New Roman", "hello"), giveme("Times New Roman", "hannah"), giveme("Times New Roman", "test") };

1 font, 9 Glyph Runs (XpsFontSubsetter scenario)

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 1,401.2 ns 5.46 ns 5.11 ns 0.1087 1,063 B 1832 B
PR_EDIT 878.1 ns 3.87 ns 3.43 ns 0.1020 1,394 B 1712 B
Benchmark data source
yield return new List<GlyphRun>() { giveme("Consolas", "hello"), giveme("Consolas", "hannah"), giveme("Consolas", "test"),
                                    giveme("Consolas", "hello"), giveme("Consolas", "hannah"), giveme("Consolas", "test"),
                                    giveme("Consolas", "hello"), giveme("Consolas", "hannah"), giveme("Consolas", "Okay, lets change this a bit!") };

Customer Impact

Improved performance, slightly decreased allocations. This is used by the XpsFontSubsetter, so it could gain a bit of perf.

Regression

No.

Testing

Local build.

Risk

Low, just a simple swap.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners October 26, 2024 12:36
@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 Oct 26, 2024
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 PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant