-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Avoid dependency on LINQ orderby iterators when building exception message #53123
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
Conversation
|
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsSaves about 2k compressed for Blazor default template
|
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteChain.cs
Outdated
Show resolved
Hide resolved
|
This saves 2K because it's the only remaining LINQ in the default code path? |
Yep, the only usage of OrderBy + dependencies |
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteChain.cs
Outdated
Show resolved
Hide resolved
8993385 to
a9e7356
Compare
…sssage Saves about 2k compressed for Blazor default template
| var ordered = new List<KeyValuePair<Type, ChainItemInfo>>(_callSiteChain); | ||
| ordered.Sort((a, b) => a.Value.Order.CompareTo(b.Value.Order)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this could avoid the List and just use an array, e.g.
var ordered = new KeyValuePair<Type, ChainItemInfo>[_callSiteChain.Length];
((ICollection<KeyValuePair<TKey, TValue>>)_callSiteChain).CopyTo(ordered, 0);
Array.Sort(ordered, (a, b) => a.Value.Order.CompareTo(b.Value.Order));That'll also let the compiler change the subsequent foreach into a for loop.
Regardless, nice to see the unnecessary OrderBy removal.
| var ordered = new List<KeyValuePair<Type, ChainItemInfo>>(_callSiteChain); | ||
| ordered.Sort((a, b) => a.Value.Order.CompareTo(b.Value.Order)); | ||
|
|
||
| foreach (KeyValuePair<Type, ChainItemInfo> pair in ordered) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The below if/else could also be simplified:
builder.Append(TypeNameHelper.GetTypeDisplayName(serviceType));
if (implementationType != null && serviceType != implementationType)
{
builder.Append('(')
.Append(TypeNameHelper.GetTypeDisplayName(implementationType))
.Append(')');
}
Saves about 2k compressed for Blazor default template