Skip to content

New FeatureCollection constructor for initialCapacity #31249

Closed
@NinoFloris

Description

@NinoFloris

Background and Motivation

Some background can be found here, dictionary resizes were fairly visible in traces #31240

Proposed API

namespace Microsoft.AspNetCore.Http.Features
{
    public class FeatureCollection
    {
+       public FeatureCollection(int initialCapacity);
    }
}

Usage Examples

Initial place this will be used is

        public DefaultHttpContext()
            : this(new FeatureCollection(10)) // right here
        {
            Features.Set<IHttpRequestFeature>(new HttpRequestFeature());
            Features.Set<IHttpResponseFeature>(new HttpResponseFeature());
            Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(Stream.Null));
            // At least some slots left before resize for storing RequestAborted feature, Services and other such things. 
        }

The initial capacity of 10 is just an example, say 5 or 7 would also be fine for me.

Alternative Designs

This could also be handled through an internal constructor.

Risks

It can be viewed as api bloat if it provides minimal overall value.

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing onegood first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions