Skip to content
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

Optimize Color/Brush parsing and string conversion, reduce allocs #10225

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Contributor

@h3xds1nz h3xds1nz commented Jan 4, 2025

Currently blocked by #9364 / #9669, hence draft.

Description

Optimizes parsing of colors and brushes from string and also conversion of colors to string.
It currently cherry-picks #9669 with additional modification for non-PBT assemblies and also the ref-struct tokenizer from #9364, but it is directly dependent due to several changes over those previously done.

ParseContextColor (normal)

Method Mean [ns] Error [ns] StdDev [ns] Code Size [B] Gen0 Allocated [B]
Original 528.9 ns 10.28 ns 13.01 ns 3,138 B 0.0763 1288 B
PR__EDIT 331.3 ns 2.51 ns 2.22 ns 1,517 B 0.0114 192 B

ParseContextColor (edge case)

Method Mean [ns] Error [ns] StdDev [ns] Code Size [B] Gen0 Allocated [B]
Original 687.2 ns 6.62 ns 5.87 ns 2,971 B 0.1040 1752 B
PR__EDIT 384.9 ns 0.90 ns 0.84 ns 1,517 B 0.0114 192 B

ToString with Round-trip format

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 425.0 ns 1.64 ns 1.37 ns 0.0181 3,864 B 304 B
PR__EDIT 321.7 ns 0.89 ns 0.79 ns 0.0048 833 B 80 B

ToString with ColorContext

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
Original 601.2 ns 4.31 ns 3.60 ns 0.0668 4,029 B 1120 B
PR__EDIT 419.1 ns 1.29 ns 1.15 ns 0.0138 1,506 B 232 B

Source data

// Benchmark 1
"ContextColor file://C:/Windows/system32/spool/drivers/color/RSWOP.icm 1.0, 0.0, 0.5, 1.0, 1.0"
// Benchmark 2
"ContextColor file://C:/Windows/system32/spool/drivers/color/RSWOP.icm 1.0,            1.0, 0.5,       0.0,       1.0"
// Benchmark 3+4
private static MILColorF scRgbColor = new() { a = 0.7667f, b = 0.2254f, g = 1.0f, r = 0.8458488f };
// Benchmark 4
uriString = "file://C:/Windows/system32/spool/drivers/color/RSWOP.icm",

Customer Impact

Improved performance, decreased allocations.

Regression

No.

Testing

Local build, assert tests.

Risk

Low to medium; will follow-up with unit tests once we're in that timeframe and past WPF tests.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners January 4, 2025 20:32
@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 Jan 4, 2025
@h3xds1nz h3xds1nz marked this pull request as draft January 4, 2025 20:33
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 draft 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