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

Remove closure allocations from ServiceCollectionDescriptorExtensions #44696

Merged

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented Nov 15, 2020

Drops the closure allocations for Func<ServiceDescriptor, Boolean> from 754 objects to 2 for startup allocations of an ASP.NET MVC app

Before

image

After

image

Contributes to #44598

@ghost
Copy link

ghost commented Nov 15, 2020

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

Issue Details
Description:

Drops the closure allocations for Func<ServiceDescriptor, Boolean> from 754 objects to 2 for startup allocations of an ASP.NET MVC app

Before

image

After

image

Author: benaadams
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

{
// Already added
return;
}
Copy link
Member

@stephentoub stephentoub Nov 15, 2020

Choose a reason for hiding this comment

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

How many times are these methods called in a typical startup? The fact that you said it's saving ~750 closures suggests it's called to add that many services, and this is O(N^2) (for each service looking at every other service already added)?

Copy link
Member Author

@benaadams benaadams Nov 15, 2020

Choose a reason for hiding this comment

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

Yep definitely is; can't get the call counts atm as Tracing in dotTrace is broken for me atm 😢

Copy link
Member

Choose a reason for hiding this comment

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

It'd be good to understand the actual cost. While saving 750 allocations is good, I'd expect saving 250,000 interface dispatches to be better ;-)

Copy link
Member

Choose a reason for hiding this comment

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

The service collection needs to store a dictionary and introduce a new interface to check if a service type already exists

@eerhardt eerhardt merged commit 7426c10 into dotnet:master Nov 18, 2020
@benaadams benaadams deleted the ServiceCollectionDescriptorExtensions branch November 18, 2020 19:57
@adamsitnik adamsitnik added the tenet-performance Performance related issue label Dec 11, 2020
@adamsitnik adamsitnik added this to the 6.0.0 milestone Dec 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 10, 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