Skip to content

Reduce delegate invocations and enumeration. #28468

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

paulomorgado
Copy link
Contributor

@paulomorgado paulomorgado commented Dec 7, 2020

The existing code is using 2 delegate invocations when, as it is, only one is needed.

var duplicates = endpoints
                .GroupBy(e => GetEndpointName(e))
                .Where(g => g.Key != null && g.Count() > 1);

The grouping of null endpoints could be avoided, but the overall cost could be highier:

var duplicates = endpoints
    .Select(e => (endpoint: e, key: GetEndpointName(e)))
    .Where(i => i.key is not null)
    .GroupBy(i => i.Key, i => i.endpoint)
    .Where(g => g.Count() > 1);

@ghost ghost added the area-servers label Dec 7, 2020
@mkArtakMSFT mkArtakMSFT added community-contribution Indicates that the PR has been added by a community member and removed community-contribution Indicates that the PR has been added by a community member labels Dec 7, 2020
@paulomorgado paulomorgado force-pushed the paulomorgado/reduce-delegates-and-enumerations branch from 8d60516 to 2bf4dae Compare December 8, 2020 20:51
@BrennanConroy BrennanConroy merged commit 5602350 into dotnet:master Dec 28, 2020
@BrennanConroy BrennanConroy added this to the 6.0-preview1 milestone Dec 28, 2020
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants