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

Janky TaskItem equality check to verify performance #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion src/Build/BackEnd/Components/RequestBuilder/TargetEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ internal async Task ExecuteTarget(ITaskBuilder taskBuilder, BuildRequestEntry re
}
else
{
HashSet<TaskItem> addedItems = new HashSet<TaskItem>();

HashSet<TaskItem> addedItems = new HashSet<TaskItem>(new DeepItemEqualityComparer());
foreach (ItemBucket bucket in batchingBuckets)
{
IList<TaskItem> itemsToAdd = bucket.Expander.ExpandIntoTaskItemsLeaveEscaped(targetReturns, ExpanderOptions.ExpandAll, targetReturnsLocation);
Expand Down Expand Up @@ -669,6 +670,15 @@ internal async Task ExecuteTarget(ITaskBuilder taskBuilder, BuildRequestEntry re
}
}

public class DeepItemEqualityComparer : IEqualityComparer<TaskItem>
{
public bool Equals(TaskItem x, TaskItem y) => x.Equals(y);
public int GetHashCode(TaskItem obj)
{
return obj.GetHashCodeDeep();
}
}

/// <summary>
/// Retrieves the error targets for this target.
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions src/Build/Instance/ProjectItemInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,45 @@ public override int GetHashCode()
return StringComparer.OrdinalIgnoreCase.GetHashCode(ItemSpec);
}

public int GetHashCodeDeep()
{
var hash = this.GetHashCode();

// var thisNames = new HashSet<string>(MSBuildNameIgnoreCaseComparer.Default);

// if (_itemDefinitions is not null)
// {
// foreach (ProjectItemDefinitionInstance itemDefinition in _itemDefinitions)
// {
// thisNames.UnionWith(itemDefinition.MetadataNames);
// }
// }

// if (_directMetadata is not null)
// {
// foreach (ProjectMetadataInstance metadatum in _directMetadata)
// {
// thisNames.Add(metadatum.Name);
// }
// }

// ITaskItem2 thisAsITaskItem2 = this;

// foreach(var name in thisNames)
// {
// var value = thisAsITaskItem2.GetMetadataValueEscaped(name).ToLowerInvariant();
// hash = hash * 23 + value.GetHashCode();
// }

foreach (var metadatum in this.MetadataCollection)
{
hash = hash * 23 + metadatum.Name.ToLowerInvariant().GetHashCode();
hash = hash * 23 + metadatum.EvaluatedValueEscaped.ToLowerInvariant().GetHashCode();
}

return hash;
}

/// <summary>
/// Override of Equals
/// </summary>
Expand Down