Skip to content

Conversation

@marek-safar
Copy link
Contributor

Saves about 2k compressed for Blazor default template

@ghost
Copy link

ghost commented May 22, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Saves about 2k compressed for Blazor default template

Author: marek-safar
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@marek-safar marek-safar requested a review from eerhardt May 22, 2021 10:23
@eerhardt eerhardt requested a review from davidfowl May 22, 2021 15:59
@davidfowl
Copy link
Member

This saves 2K because it's the only remaining LINQ in the default code path?

@marek-safar
Copy link
Contributor Author

This saves 2K because it's the only remaining LINQ in the default code path?

Yep, the only usage of OrderBy + dependencies

@marek-safar marek-safar force-pushed the di2 branch 2 times, most recently from 8993385 to a9e7356 Compare May 23, 2021 06:17
…sssage

Saves about 2k compressed for Blazor default template
Comment on lines +52 to +53
var ordered = new List<KeyValuePair<Type, ChainItemInfo>>(_callSiteChain);
ordered.Sort((a, b) => a.Value.Order.CompareTo(b.Value.Order));
Copy link
Member

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)
Copy link
Member

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(')');
}

@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants