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: reduce allocations and calls to ToArray #2747

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

Evangelink
Copy link
Member

No description provided.

@@ -272,7 +272,7 @@ protected IEnumerable<string> Deploy(IList<DeploymentItem> deploymentItems, stri
/// <param name="isDirectory">Is this a directory.</param>
/// <returns>Paths to items to deploy.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")]
protected string[]? GetFullPathToFilesCorrespondingToDeploymentItem(DeploymentItem deploymentItem, string testSource, string resultsDirectory, IList<string> warnings, out bool isDirectory)
protected List<string>? GetFullPathToFilesCorrespondingToDeploymentItem(DeploymentItem deploymentItem, string testSource, string resultsDirectory, IList<string> warnings, out bool isDirectory)
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IList/IReadOnlyList?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only internal/private stuff so I prefer to always be as specific as possible.

#endif
}

#if NETFRAMEWORK
internal static object[] GetCustomAttributes(Assembly assembly, Type type)
internal static List<Attribute> GetCustomAttributes(Assembly assembly, Type type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

@MarcoRossignoli MarcoRossignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A profiling before/after could be interesting

@nohwnd
Copy link
Member

nohwnd commented Apr 23, 2024

I get the intent here, for stuff like ToArray().Length == 1, but for example the change in src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs makes the api pretty jagged, where some parts return ICollection and some return IEnumerable, just because some items need filtering and some don't.

In most cases we will enumerate the collection eventually, so is there that much work that we are saving by not putting it in array or some other ICollection?

@Evangelink Evangelink merged commit 71eae08 into microsoft:main Apr 23, 2024
5 of 7 checks passed
@Evangelink Evangelink deleted the opt branch April 23, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants