maui
maui copied to clipboard
Minor optimization for `MergedStyle.SetStyle`
Description of Change
This PR just removes a few allocations. There is no big idea.
Benchmark
cd src/Core/tests/Benchmarks
dotnet build -c Release --framework net8.0 && dotnet run --framework net8.0 -c Release -- --runtimes net8.0 --filter *StyleBenchmarker*
MAIN
| Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|---|
| MergedStyle | 66.18 us | 2.060 us | 5.977 us | 63.38 us | 4.5166 | 4.3945 | 0.7324 | 28.25 KB |
PR
| Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|---|
| MergedStyle | 64.74 us | 1.820 us | 5.367 us | 62.34 us | 4.5166 | 4.3945 | 0.7324 | 28.25 KB |
The improvement is not really big but I find it better than nothing.
Additional findings
- It appears that
MergedStyle.ReRegisterImplicitStylesis not in use (at least not in this repo). - CA1859 is reported on line https://github.com/dotnet/maui/blob/d7dac41200a932ea748569a28b6f26e7e3df69db/src/Controls/src/Core/MergedStyle.cs#L15 and it looks like it can be trivially changed and nothing wrong would happen.
Issues Fixed
Fixes #21539
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@StephaneDelcroix Does this PR make sense to you please?
@jonathanpeppers Does the proposed changes make sense to you please?