Maui.Markup icon indicating copy to clipboard operation
Maui.Markup copied to clipboard

Optimize `TextAlignmentExtensionsGenerator`

Open TheCodeTraveler opened this issue 1 year ago • 1 comments

Description of Change

This PR improves the performance of TextAlignmentExtensionsGenerator, optimizing for memory allocations and processing time.

This PR also adds Unit Tests + Benchmarks for CommunityToolkit.Maui.Markup.SourceGenerators to ensure no regressions between the previous implementation of TextAlignmentExtensionsGenerator and this updated/optimized implementation.

PR Checklist

  • [x] Has tests (if omitted, state reason in description)
  • [x] Has samples (if omitted, state reason in description)
  • [x] Rebased on top of main at time of PR
  • [x] Changes adhere to coding standard

Additional information

TheCodeTraveler avatar Oct 04 '24 21:10 TheCodeTraveler

Here's the current benchmark results. It looks like I still have some work to do to optimize the SourceGenerator to reduce memory allocations

Current / Previous TextAlignmentExtensionsGenerator

Method Mean Error StdDev Median Gen0 Allocated
VerifyGeneratedSource_WhenClassIsGeneric 70.92 ms 7.361 ms 20.15 ms 61.36 ms 333.3333 9.48 MB
VerifyGeneratedSource_WhenClassImplementsITextAlignmentInterface 67.18 ms 4.793 ms 12.96 ms 61.78 ms 333.3333 9.4 MB

Updated TextAlignmentExtensionsGenerator

Method Mean Error StdDev Median Gen0 Allocated
VerifyGeneratedSource_WhenClassIsGeneric 65.35 ms 5.100 ms 14.13 ms 59.63 ms 333.3333 10.49 MB
VerifyGeneratedSource_WhenClassImplementsITextAlignmentInterface 66.48 ms 6.051 ms 16.67 ms 58.66 ms 333.3333 10.42 MB

TheCodeTraveler avatar Oct 06 '24 23:10 TheCodeTraveler