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 TextAlignmentExtensionsGenerator #321

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f64408a
Add Unit Tests
brminnick Oct 4, 2024
3d80496
Update TextAlignmentExtensionsGenerator.cs
brminnick Oct 4, 2024
2fac95b
Update Tests
brminnick Oct 4, 2024
93e985b
Fix Unit Tests
brminnick Oct 4, 2024
9f51055
Update TextAlignmentExtensionsTests.cs
brminnick Oct 4, 2024
7dd2c3f
Update azure-pipelines.yml
brminnick Oct 4, 2024
f751a62
Remove Generated File Name
brminnick Oct 4, 2024
f661c5f
Refactor TextAlignmentExtensionsGenerator
brminnick Oct 6, 2024
83eb152
Update Source Generator
brminnick Oct 6, 2024
064be4b
Update TextAlignmentExtensionsGenerator.cs
brminnick Oct 6, 2024
6d8f1ef
Merge branch 'main' into Update-Analyzers
brminnick Oct 6, 2024
1744eee
Remove temporary variable
brminnick Oct 6, 2024
44be926
Merge branch 'Update-Analyzers' of https://github.com/CommunityToolki…
brminnick Oct 6, 2024
1e00aea
Refactor Source Generator
brminnick Oct 6, 2024
8b00b91
Update CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests.csproj
brminnick Oct 6, 2024
696fbf3
Add Benchmarks
brminnick Oct 6, 2024
30d55d8
Update TextAlignmentExtensionsGeneratorBenchmarks.cs
brminnick Oct 6, 2024
f8697d0
Remove `PrivateAssets`
brminnick Oct 6, 2024
2ed054e
Remove unnecessary NuGet Packages
brminnick Oct 6, 2024
efa18ff
Update TextAlignmentExtensionsGenerator.cs
brminnick Oct 6, 2024
f93e9d9
Revert Source Generator for Benchmarking
brminnick Oct 6, 2024
59c136f
Revert "Revert Source Generator for Benchmarking"
brminnick Oct 6, 2024
14743ab
Merge branch 'main' into Update-Analyzers
brminnick Nov 12, 2024
7130bb0
Merge branch 'main' into Update-Analyzers
brminnick Nov 25, 2024
22ab532
Merge branch 'main' into Update-Analyzers
brminnick Nov 26, 2024
9937498
Merge branch 'main' into Update-Analyzers
brminnick Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ variables:
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.Markup.UnitTests/CommunityToolkit.Maui.Markup.UnitTests.csproj'
PathToCommunityToolkitBenchmarkCsproj: 'src/CommunityToolkit.Maui.Markup.Benchmarks/CommunityToolkit.Maui.Markup.Benchmarks.csproj'
PathToCommunityToolkitSourceGeneratorsCsproj: 'src/CommunityToolkit.Maui.Markup.SourceGenerators/CommunityToolkit.Maui.Markup.SourceGenerators.csproj'
PathToCommunityToolkitSourceGeneratorsUnitTestCsproj: 'src/CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests/CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests.csproj'
PathToCommunityToolkitSourceGeneratorsBenchmarkCsproj: 'src/CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks/CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks.csproj'
CommunityToolkitSampleApp_Xcode_Version: '16'
CommunityToolkitLibrary_Xcode_Version: '16'
ShouldCheckDependencies: true
Expand Down Expand Up @@ -190,6 +192,11 @@ jobs:
script: 'dotnet build -c Release $(PathToCommunityToolkitUnitTestCsproj)'

# test
- task: CmdLine@2
displayName: 'Run Source Generators Unit Tests'
inputs:
script: 'dotnet test -c Release $(PathToCommunityToolkitSourceGeneratorsUnitTestCsproj) --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory $(Agent.TempDirectory)'

- task: CmdLine@2
displayName: 'Run Unit Tests'
inputs:
Expand Down Expand Up @@ -306,10 +313,15 @@ jobs:
script: dotnet --info

- task: CmdLine@2
displayName: 'Run Benchmarks'
displayName: 'Run Library Benchmarks'
inputs:
script : 'dotnet run --project $(PathToCommunityToolkitBenchmarkCsproj) -c Release -- -a $(Build.ArtifactStagingDirectory)'

- task: CmdLine@2
displayName: 'Run Source Generator Benchmarks'
inputs:
script : 'dotnet run --project $(PathToCommunityToolkitSourceGeneratorsBenchmarkCsproj) -c Release -- -a $(Build.ArtifactStagingDirectory)'

# publish the Benchmark Results
- task: PublishBuildArtifacts@1
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
Expand Down
22 changes: 21 additions & 1 deletion samples/CommunityToolkit.Maui.Markup.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{A919
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Markup.SourceGenerators", "..\src\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.csproj", "{533792FE-99CD-4B5B-A8B2-51A8BE3852A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Maui.Markup.Benchmarks", "..\src\CommunityToolkit.Maui.Markup.Benchmarks\CommunityToolkit.Maui.Markup.Benchmarks.csproj", "{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Markup.Benchmarks", "..\src\CommunityToolkit.Maui.Markup.Benchmarks\CommunityToolkit.Maui.Markup.Benchmarks.csproj", "{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests", "..\src\CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests\CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests.csproj", "{26D5485B-68EA-454A-BBB7-11C6FF9B1B98}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{6F9076FC-4329-417E-80ED-0B57CBBC4BDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{16554827-15BF-471E-B979-11A9D16A058B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks", "..\src\CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks\CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks.csproj", "{1CB34564-4764-4102-AD84-1C11960C97E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -50,12 +58,24 @@ Global
{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E}.Release|Any CPU.Build.0 = Release|Any CPU
{26D5485B-68EA-454A-BBB7-11C6FF9B1B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26D5485B-68EA-454A-BBB7-11C6FF9B1B98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26D5485B-68EA-454A-BBB7-11C6FF9B1B98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26D5485B-68EA-454A-BBB7-11C6FF9B1B98}.Release|Any CPU.Build.0 = Release|Any CPU
{1CB34564-4764-4102-AD84-1C11960C97E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CB34564-4764-4102-AD84-1C11960C97E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CB34564-4764-4102-AD84-1C11960C97E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CB34564-4764-4102-AD84-1C11960C97E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A15CD688-94E8-483B-8B87-A173B2DD0E40} = {A919D3AA-043D-441B-9DF5-18ED84B7FC08}
{F45A2C29-DDD2-49A8-B4D9-57150F80AD36} = {16554827-15BF-471E-B979-11A9D16A058B}
{8C1B7D06-75D7-40AC-9FDB-344BF5FCCD5E} = {6F9076FC-4329-417E-80ED-0B57CBBC4BDC}
{26D5485B-68EA-454A-BBB7-11C6FF9B1B98} = {16554827-15BF-471E-B979-11A9D16A058B}
{1CB34564-4764-4102-AD84-1C11960C97E9} = {6F9076FC-4329-417E-80ED-0B57CBBC4BDC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<Configuration>Release</Configuration>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests\CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;

namespace CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks;
public class Program
{
public static void Main(string[] args)
{
var config = DefaultConfig.Instance;
var summary = BenchmarkRunner.Run<TextAlignmentExtensionsGeneratorBenchmarks>(config, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BenchmarkDotNet.Attributes;
using CommunityToolkit.Maui.Markup.SourceGenerators.UnitTests;

namespace CommunityToolkit.Maui.Markup.SourceGenerators.Benchmarks;

[MemoryDiagnoser]
public class TextAlignmentExtensionsGeneratorBenchmarks
{
readonly TextAlignmentExtensionsGeneratorTests textAlignmentExtensionsGeneratorTests = new();

[Benchmark]
public Task VerifyGeneratedSource_WhenClassIsGeneric()
{
return textAlignmentExtensionsGeneratorTests.VerifyGeneratedSource_WhenClassIsGeneric();
}

[Benchmark]
public Task VerifyGeneratedSource_WhenClassImplementsITextAlignmentInterface()
{
return textAlignmentExtensionsGeneratorTests.VerifyGeneratedSource_WhenClassImplementsITextAlignmentInterface();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit" Version="1.1.2" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Maui.Markup.SourceGenerators\CommunityToolkit.Maui.Markup.SourceGenerators.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui.Markup\CommunityToolkit.Maui.Markup.csproj" />
</ItemGroup>

</Project>
Loading
Loading