Skip to content

Commit

Permalink
perf: Merge all system resource dictionaries to improve lookup perfor…
Browse files Browse the repository at this point in the history
…mance
  • Loading branch information
jeromelaban committed Jan 4, 2022
1 parent 4943d5b commit 6d49af8
Show file tree
Hide file tree
Showing 9 changed files with 22,284 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ private bool IsUnoAssembly
private bool IsUnoFluentAssembly
=> _defaultNamespace == "Uno.UI.FluentTheme" || _defaultNamespace.StartsWith("Uno.UI.FluentTheme.v");

/// <summary>
/// Resource files that should be initialized first, in given order, because other resource declarations depend on them.
/// </summary>
private static readonly string[] _baseResourceDependencies = new[]
{
"SystemResources.xaml",
"Generic.xaml",
"Generic.Native.xaml",
};

private const string WinUIThemeResourcePathSuffixFormatString = "themeresources_v{0}.xaml";
private static string WinUICompactPathSuffix = Path.Combine("DensityStyles", "Compact.xaml");

Expand Down Expand Up @@ -696,7 +686,7 @@ private string GenerateGlobalResources(IEnumerable<XamlFileDefinition> files, Xa
if (IsUnoAssembly && _xamlSourceFiles.Any())
{
// Build master dictionary
foreach (var dictProperty in map.GetAllDictionaryProperties(_baseResourceDependencies))
foreach (var dictProperty in map.GetAllDictionaryProperties())
{
writer.AppendLineInvariant("MasterDictionary.MergedDictionaries.Add({0});", dictProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ private void BuildTopLevelResourceDictionaryInitializers(IIndentedStringBuilder
{
var key = GetDictionaryResourceKey(resource);

if (key == null)
if (key == null || resource.Members.Any(m => m.Member.Name == "IsNativeStyle"))
{
continue;
}
Expand All @@ -1277,7 +1277,7 @@ private void BuildTopLevelResourceDictionaryInitializers(IIndentedStringBuilder
{
var key = GetDictionaryResourceKey(resource);

if (key == null)
if (key == null || resource.Members.Any(m => m.Member.Name == "IsNativeStyle"))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,8 @@ internal void Add(string staticResourceKey, string ns, ResourcePrecedence preced
/// <param name="initialFiles">File names of the ResourceDictionaries whose properties should be returned first.</param>
/// <param name="ignoredFiles">Files which shouldn't be included in the default system resources</param>
/// <remarks>This is used when building Uno.UI itself to create a master dictionary of system resources.</remarks>
internal IEnumerable<string> GetAllDictionaryProperties(string[] initialFiles)
{
var initialProperties = initialFiles.Select(f =>
_rdMap.First(kvp =>
kvp.Key.EndsWith(f, StringComparison.InvariantCultureIgnoreCase)
)
)
.ToArray();

return initialProperties.Concat(
_rdMap.Except(initialProperties)
)
.Select(kvp => ConvertIdToResourceDictionaryProperty(kvp.Value.UniqueID));
}
internal IEnumerable<string> GetAllDictionaryProperties()
=> _rdMap.Select(kvp => ConvertIdToResourceDictionaryProperty(kvp.Value.UniqueID));

/// <summary>
/// Gets the name of a GlobalStaticResources property associated with a ResourceDictionary.Source designation. Throws an exception if none is found.
Expand Down
22,251 changes: 22,251 additions & 0 deletions src/Uno.UI/Generated/mergedpages.xaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Uno.UI/Uno.UI.Skia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

<Import Project="..\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props" />
<Import Project="..\Uno.UI\MixinGeneration.targets" />
<Import Project="..\Uno.UI\XamlMerge.targets" />

<Target Name="_UnoToolkitOverrideNuget" AfterTargets="AfterBuild" DependsOnTargets="BuiltProjectOutputGroup" Condition="'$(UnoNugetOverrideVersion)'!=''">

Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/Uno.UI.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@

<Import Project="..\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props" />
<Import Project="..\Uno.UI\MixinGeneration.targets" />
<Import Project="..\Uno.UI\XamlMerge.targets" />

<Target Name="_UnoUIWasmOverrideNuget" AfterTargets="AfterBuild" DependsOnTargets="BuiltProjectOutputGroup" Condition="'$(UnoNugetOverrideVersion)'!=''">

Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/Uno.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
</Target>

<Import Project="MixinGeneration.targets" />
<Import Project="XamlMerge.targets" />

<!-- If any ItemGroup appears here with Remove=XXX, they should be deleted -->

Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/Uno.UI.net6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@
</Target>

<Import Project="MixinGeneration.targets" />
<Import Project="XamlMerge.targets" />

</Project>
24 changes: 24 additions & 0 deletions src/Uno.UI/XamlMerge.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project>
<PropertyGroup>
<_Uno_XamlMerge_Task_Version>0.1.0-dev.41</_Uno_XamlMerge_Task_Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Uno.XamlMerge.Task" Version="$(_Uno_XamlMerge_Task_Version)" />
</ItemGroup>

<ItemGroup>
<XamlMergeInput Include="@(Page)" />
</ItemGroup>

<Import Project="$(NuGetPackageRoot)uno.xamlmerge.task\$(_Uno_XamlMerge_Task_Version)\build\Uno.XamlMerge.Task.targets"
Condition="'$(TargetFramework)' == ''" />

<Target Name="_GenerateMergedXaml"
DependsOnTargets="GenerateMergedXaml"
BeforeTargets="DispatchToInnerBuilds"
Condition="'$(TargetFramework)' == ''">
</Target>

</Project>

0 comments on commit 6d49af8

Please sign in to comment.