wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Remove KnownColors static constructor

Open ThomasGoulet73 opened this issue 5 months ago • 3 comments

Description

Removes KnownColors static constructor and replaces it with uint parsing and calling Enum.IsDefined. The static constructor is called at the startup of every WPF app AFAIK (It is called even with an app created from the empty WPF template). The size of the dictionary at runtime is about 10 Kb so not much but it is still unnecessary used memory.

Benchmark results of KnownColors.ArgbStringToKnownColor
Method argbString Mean Error StdDev Ratio RatioSD Allocated Alloc Ratio
Old #FFDA70D6 15.2223 ns 0.2156 ns 0.2017 ns 1.00 0.02 - NA
New #FFDA70D6 13.6033 ns 0.0437 ns 0.0365 ns 0.89 0.01 - NA
Old #XYZ 9.1676 ns 0.0399 ns 0.0353 ns 1.00 0.01 - NA
New #XYZ 5.4110 ns 0.0116 ns 0.0097 ns 0.59 0.00 - NA
Old FFDA70D6 11.5086 ns 0.0509 ns 0.0476 ns 1.00 0.01 - NA
New FFDA70D6 0.8499 ns 0.0034 ns 0.0028 ns 0.07 0.00 - NA

Customer Impact

Better perf, better startup perf and lower static memory.

Regression

No.

Testing

Local testing.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

ThomasGoulet73 avatar Aug 28 '24 23:08 ThomasGoulet73