Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Reduce FeatureReference checking, lazy init FormFeature #999

Closed
wants to merge 4 commits into from

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented Feb 10, 2018

Update to #925

Resolves #924 "FeatureCache is over-checked and over-reset"
Resolves #677 "FormFeature allocates when unused"
Resolves #880 "Don't allocate the FormFeature eagerly per request"

/cc @davidfowl

@@ -44,15 +46,26 @@ public DefaultHttpContext()
}

public DefaultHttpContext(IFeatureCollection features)
: this(new FeatureCollection(), FormOptions.Default)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn’t we be passing the feature collection and not a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -158,7 +158,9 @@ public void UpdateFeatures_ClearsCachedFeatures()
features.Set<IHttpWebSocketFeature>(new TestHttpWebSocketFeature());

// featurecollection is set. all cached interfaces are null.
var context = new DefaultHttpContext(features);
var context = new DefaultHttpContext(features, FormOptions.Default);
Copy link
Member

Choose a reason for hiding this comment

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

Make sure we validate the default ctor as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@benaadams
Copy link
Contributor Author

Before
image

After
image

Still a bucket load of calls; but less

@@ -8,6 +8,8 @@ namespace Microsoft.AspNetCore.Http.Features
{
public class FormOptions
{
public static readonly FormOptions Default = new FormOptions();
Copy link
Member

@Tratcher Tratcher Feb 12, 2018

Choose a reason for hiding this comment

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

We can't make a mutable instance a public static. Make it internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

@@ -15,26 +15,39 @@ public class DefaultHttpRequest : HttpRequest
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func<IFeatureCollection, IHttpRequestFeature> _nullRequestFeature = f => null;
private readonly static Func<IFeatureCollection, IQueryFeature> _newQueryFeature = f => new QueryFeature(f);
private readonly static Func<HttpRequest, IFormFeature> _newFormFeature = r => new FormFeature(r);
private readonly static Func<(HttpRequest request, FormOptions options), IFormFeature> _newFormFeature = (r) => new FormFeature(r.request, r.options ?? FormOptions.Default);
Copy link
Member

Choose a reason for hiding this comment

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

Tuples? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom struct or another Fetch overload?

@natemcmaster natemcmaster changed the base branch from dev to master July 2, 2018 17:58
@muratg
Copy link

muratg commented Oct 10, 2018

@davidfowl @Tratcher is this still relevant/useful in your opinion? If so, let's move it forward. If not, let's get it closed.

Ben, thanks for the PR!

@muratg muratg added this to the 2.2.0-preview3 milestone Oct 10, 2018
@davidfowl
Copy link
Member

@benaadams I'm going to move this to 3.0

@davidfowl davidfowl modified the milestones: 2.2.0-preview3, 3.0.0 Nov 5, 2018
@natemcmaster
Copy link
Contributor

@davidfowl I'm about to merge this repo into aspnet/AspNetCore. If you'd like this PR merged, can you bring it in today? If not, I'm going to close this and you'll have to re-open the PR.

@davidfowl
Copy link
Member

@natemcmaster close it and I'll make @benaadams reopen it 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants