maui icon indicating copy to clipboard operation
maui copied to clipboard

Minor optimization for `MergedStyle.SetStyle`

Open MartyIX opened this issue 1 year ago • 3 comments

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

  1. It appears that MergedStyle.ReRegisterImplicitStyles is not in use (at least not in this repo).
  2. 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

MartyIX avatar Mar 30 '24 21:03 MartyIX

/azp run

rmarinho avatar Apr 01 '24 10:04 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Apr 01 '24 10:04 azure-pipelines[bot]

@StephaneDelcroix Does this PR make sense to you please?

MartyIX avatar Apr 12 '24 11:04 MartyIX

@jonathanpeppers Does the proposed changes make sense to you please?

MartyIX avatar Apr 19 '24 09:04 MartyIX