Remove unnecessary GetTypeInfo from Microsoft.Extensions.#44891
Remove unnecessary GetTypeInfo from Microsoft.Extensions.#44891stephentoub merged 1 commit intodotnet:masterfrom
Conversation
I also made a slight optimization to CallSiteFactory to use ToArray instead of ToList.
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
Tagging subscribers to this area: @eerhardt, @maryamariyan DetailsIssue Details
|
|
Nice clean up. We should do this in ASP.NET too... |
Will log an issue (and maybe make a PR if it looks quick). |
stephentoub
left a comment
There was a problem hiding this comment.
(Some of this LINQ usage pains me to look at :), but that's not related to your PR.)
| { | ||
| _stackGuard = new StackGuard(); | ||
| _descriptors = descriptors.ToList(); | ||
| _descriptors = descriptors.ToArray(); |
There was a problem hiding this comment.
What was the benefit of this change? Is _descriptors accessed a lot such that the overhead of going through _descriptors as a list vs an array mattered?
There was a problem hiding this comment.
The benefit was very minimal, probably not even observable. I started this change by looking at CallSiteFactory.Populate (which is 75% of the above benchmark). And this ToList() jumped out at me and looking at the code I noticed we don't need a List, but can just use an Array instead. I just figured while I was in here, it was one less object to create.
There was a problem hiding this comment.
I just figured while I was in here, it was one less object to create.
But unless the array is the exact right size, ToArray needs to allocate one at the end and copy all the elements to it. ToList doesn't. So you still generally end up with another object, but typically a bigger one.
There was a problem hiding this comment.
In this case, the Type that is passed in to descriptors is always an IServiceCollection, which implements ICollection<T>. So the size will be known up-front and only a single Array needs to be allocated. It won't need to be resized in the end.
I also made a slight optimization to CallSiteFactory to use ToArray instead of ToList.
These were showing up as 5% of
ServiceCollection.BuildServiceProvider()in a simple benchmark: