-
Notifications
You must be signed in to change notification settings - Fork 191
Reduce FeatureReference checking, lazy init FormFeature #999
Conversation
@@ -44,15 +46,26 @@ public DefaultHttpContext() | |||
} | |||
|
|||
public DefaultHttpContext(IFeatureCollection features) | |||
: this(new FeatureCollection(), FormOptions.Default) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
9aff7c4
to
d1649ea
Compare
@@ -8,6 +8,8 @@ namespace Microsoft.AspNetCore.Http.Features | |||
{ | |||
public class FormOptions | |||
{ | |||
public static readonly FormOptions Default = new FormOptions(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuples? 😄
There was a problem hiding this comment.
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?
@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! |
@benaadams I'm going to move this to 3.0 |
@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. |
@natemcmaster close it and I'll make @benaadams reopen it 😄 |
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