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

Use char overload in System.Xaml #3998

Merged

Conversation

ThomasGoulet73
Copy link
Contributor

Replace all method call that uses a single char string while there is another method that accepts a char.

Should yield tiny performance benefit on hot paths.

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner January 13, 2021 18:28
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jan 13, 2021
@ghost ghost requested review from fabiant3, ryalanms and SamBent January 13, 2021 18:28
@@ -1996,7 +1996,7 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
if (value is NameFixupToken && parentProperty != XamlLanguage.Items)
{
NameFixupToken token = value as NameFixupToken;
string names = String.Join(",", token.NeededNames.ToArray());
string names = String.Join(',', token.NeededNames.ToArray());
Copy link

@sixlettervariables sixlettervariables Jan 14, 2021

Choose a reason for hiding this comment

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

Curious, are these ToArray calls needed? It seems like NeededNames implements IEnumerable<String>. (Not that it probably matters on this exception oath)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would definetly be worth benchmarking but List may have optimization that makes it quick to return a copy of the internal array so I don't know if it is faster than enumerating with IEnumerable. My guess would be that ToArray is faster but uses more memory (It may vary with the number of item).

Copy link
Contributor

Choose a reason for hiding this comment

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

List creates a new array and copies elements over, while enumeration uses in-place value-type enumerator. It's a one method call vs. method call every item during enumerating, but also don't forget that the string.Join implementation differs - the array uses unsafe, pre-allocated char buffer while the enumerable uses StringBuilder to avoid double enumeration, and another difference is that changing the collection while being enumerated is illegal and throws.

That said, it probably doesn't matter here as it's an exception path and the number of items in the list would typically be quite small.

@ryalanms
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ryalanms
Copy link
Member

ryalanms commented Feb 8, 2021

Thank you for your contribution, @ThomasGoulet73.

@ryalanms ryalanms merged commit 798072c into dotnet:master Feb 8, 2021
@ThomasGoulet73 ThomasGoulet73 deleted the system-xaml-use-char-overload branch February 8, 2021 23:18
@ghost ghost locked as resolved and limited conversation to collaborators Apr 10, 2022
@ghost ghost assigned ThomasGoulet73 May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants