Skip to content

Commit

Permalink
perf: Misc linker hints updates
Browse files Browse the repository at this point in the history
Adds various pre-checks for linker hint substitutions to improve XAML trimming.
  • Loading branch information
jeromelaban committed Nov 22, 2022
1 parent be63194 commit e927734
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 135 deletions.
3 changes: 3 additions & 0 deletions src/AddIns/Uno.UI.Lottie/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Reflection;

[assembly: AssemblyMetadata("IsTrimmable", "True")]
4 changes: 4 additions & 0 deletions src/AddIns/Uno.UI.Lottie/Uno.UI.Lottie.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@
<Copy SourceFiles="@(_OutputFilesPDB)" DestinationFiles="@(_OutputFilesPDB->'$(_TargetNugetFolder)\%(RecursiveDir)%(Filename).pdb')" />
</Target>

<ItemGroup>
<SourceGeneratorInput Remove="AssemblyInfo.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ from type in module.GlobalNamespace.GetNamespaceTypes()
bindableTypes = bindableTypes.ToArray();

context.AddSource("DependencyObjectAvailability", GenerateTypeProviders(bindableTypes));
context.AddSource("DependencyObjectAvailability_Debug",
$"""
/*
_assemblyName:{_assemblyName}
_namedSymbolsLookup:{_namedSymbolsLookup}
_dependencyObjectSymbol:{_dependencyObjectSymbol}
modules: {string.Join(", ", modules)}
modules: {string.Join(", ", modules)}

*/
""");

GenerateLinkerSubstitutionDefinition(bindableTypes, isApplication);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ private static bool FastStringConvert(Type outputType, string input, ref object

private static bool FastStringToIconElement(Type outputType, string input, ref object output)
{
if (outputType == typeof(Windows.UI.Xaml.Controls.IconElement))
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_IconElement_Available
&& outputType == typeof(Windows.UI.Xaml.Controls.IconElement))
{
output = (Windows.UI.Xaml.Controls.IconElement)input;
return true;
Expand Down Expand Up @@ -427,7 +428,8 @@ private static bool FastStringToInputScope(Type outputType, string input, ref ob

private static bool FastStringToToolTip(Type outputType, string input, ref object output)
{
if (outputType == typeof(Windows.UI.Xaml.Controls.ToolTip))
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_ToolTip_Available
&& outputType == typeof(Windows.UI.Xaml.Controls.ToolTip))
{
output = new Windows.UI.Xaml.Controls.ToolTip { Content = input };
return true;
Expand Down Expand Up @@ -509,7 +511,8 @@ private static bool FastStringToPointCollection(Type outputType, string input, r
private static bool FastStringToPath(Type outputType, string input, ref object output)
{
#if __WASM__
if (outputType == typeof(Geometry))
if (__LinkerHints.Is_Windows_UI_Xaml_Media_Geometry_Available
&& outputType == typeof(Geometry))
{
output = (Geometry)input;

Expand Down Expand Up @@ -613,7 +616,8 @@ private static bool FastStringToColorConvert(Type outputType, string input, ref

private static bool FastStringToImageSource(Type outputType, string input, ref object output)
{
if (outputType == typeof(Windows.UI.Xaml.Media.ImageSource))
if (__LinkerHints.Is_Windows_UI_Xaml_Media_ImageSource_Available
&& outputType == typeof(Windows.UI.Xaml.Media.ImageSource))
{
output = (Windows.UI.Xaml.Media.ImageSource)input;
return true;
Expand Down
17 changes: 14 additions & 3 deletions src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,20 @@ public static class Style
/// </summary>
public static void ConfigureNativeFrameNavigation()
{
SetUWPDefaultStylesOverride<Frame>(useUWPDefaultStyle: false);
SetUWPDefaultStylesOverride<Windows.UI.Xaml.Controls.CommandBar>(useUWPDefaultStyle: false);
SetUWPDefaultStylesOverride<Windows.UI.Xaml.Controls.AppBarButton>(useUWPDefaultStyle: false);
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Frame_Available)
{
SetUWPDefaultStylesOverride<Frame>(useUWPDefaultStyle: false);
}

if (__LinkerHints.Is_Windows_UI_Xaml_Controls_CommandBar_Available)
{
SetUWPDefaultStylesOverride<Windows.UI.Xaml.Controls.CommandBar>(useUWPDefaultStyle: false);
}

if (__LinkerHints.Is_Windows_UI_Xaml_Controls_AppBarButton_Available)
{
SetUWPDefaultStylesOverride<Windows.UI.Xaml.Controls.AppBarButton>(useUWPDefaultStyle: false);
}
}

/// <summary>
Expand Down
38 changes: 28 additions & 10 deletions src/Uno.UI/UI/Xaml/Automation/AutomationProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,35 @@ public static void SetAutomationId(DependencyObject element, string value)
new FrameworkPropertyMetadata(default(AutomationLandmarkType)));

#if __WASM__
private static string FindHtmlRole(UIElement uIElement) =>
uIElement switch
private static string FindHtmlRole(UIElement uIElement)
{
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Button_Available && uIElement is Button)
{
return "button";
}
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_RadioButton_Available && uIElement is RadioButton)
{
return "radio";
}
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_CheckBox_Available && uIElement is CheckBox)
{
return "checkbox";
}
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_TextBlock_Available && uIElement is TextBlock)
{
Button _ => "button",
RadioButton _ => "radio",
CheckBox _ => "checkbox",
TextBlock _ => "label",
TextBox _ => "textbox",
Slider _ => "slider",
_ => null
};
return "label";
}
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_TextBox_Available && uIElement is TextBox)
{
return "textbox";
}
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Slider_Available && uIElement is Slider)
{
return "slider";
}

return null;
}
#endif

}
Expand Down
Loading

0 comments on commit e927734

Please sign in to comment.