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

perf: Avoid holding into symbols #11466

Merged
merged 1 commit into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#nullable enable

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;

namespace Uno.UI.SourceGenerators.XamlGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
{
internal record GenerationRunFileInfo(GenerationRunInfo RunInfo, string FileId)
{
private Dictionary<INamedTypeSymbol, int> _appliedTypes = new Dictionary<INamedTypeSymbol, int>();
private Dictionary<string, int> _appliedTypes = new Dictionary<string, int>();

internal string? ComponentCode { get; set; }

internal IReadOnlyDictionary<INamedTypeSymbol, int> AppliedTypes => _appliedTypes;
internal IReadOnlyDictionary<string, int> AppliedTypes => _appliedTypes;

internal void SetAppliedTypes(Dictionary<INamedTypeSymbol, int> appliedTypes)
internal void SetAppliedTypes(Dictionary<string, int> appliedTypes)
{
foreach (var type in appliedTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ internal partial class XamlFileGenerator
/// <summary>
/// Information about types used in .Apply() scenarios
/// </summary>
private readonly Dictionary<INamedTypeSymbol, int> _xamlAppliedTypes = new Dictionary<INamedTypeSymbol, int>();
/// <remarks>
/// The key of the dictionary is the globalized fully qualified name.
/// </remarks>
private readonly Dictionary<string, int> _xamlAppliedTypes = new();

private readonly INamedTypeSymbol _assemblyMetadataSymbol;

Expand Down Expand Up @@ -655,11 +658,11 @@ private void BuildXamlApplyBlocks(IndentedStringBuilder writer)
{
foreach (var typeInfo in _xamlAppliedTypes)
{
writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({GetGlobalizedTypeName(typeInfo.Key.ToString())} instance);");
writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({typeInfo.Key} instance);");

writer.AppendLineIndented($"[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]");
using (writer.BlockInvariant(
$"public static {GetGlobalizedTypeName(typeInfo.Key.ToString())} {_fileUniqueId}_XamlApply(this {GetGlobalizedTypeName(typeInfo.Key.ToString())} instance, XamlApplyHandler{typeInfo.Value} handler)"
$"public static {typeInfo.Key} {_fileUniqueId}_XamlApply(this {typeInfo.Key} instance, XamlApplyHandler{typeInfo.Value} handler)"
))
{
writer.AppendLineIndented($"handler(instance);");
Expand Down Expand Up @@ -4169,10 +4172,11 @@ private XamlLazyApplyBlockIIndentedStringBuilder CreateApplyBlock(IIndentedStrin

if (appliedType != null)
{
if (!_xamlAppliedTypes.TryGetValue(appliedType, out var appliedTypeIndex))
var globalizedFullyQualifiedAppliedType = GetGlobalizedTypeName(appliedType.ToString());
if (!_xamlAppliedTypes.TryGetValue(globalizedFullyQualifiedAppliedType, out var appliedTypeIndex))
MartinZikmund marked this conversation as resolved.
Show resolved Hide resolved
{
appliedTypeIndex = _xamlAppliedTypes.Count;
_xamlAppliedTypes.Add(appliedType, _xamlAppliedTypes.Count);
_xamlAppliedTypes.Add(globalizedFullyQualifiedAppliedType, _xamlAppliedTypes.Count);
}

if (_isHotReloadEnabled)
Expand Down