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

Lazy init FeatureReferences #925

Closed
wants to merge 1 commit into from

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented Aug 24, 2017

Follow up on #814 "Improve DefaultHttpXxx default paths"

Fixes #924 "FeatureCache is over-checked and over-reset"

The Context feature cache is checked and initializes the Response and Request caches at the point one is accessed, so the version check via interface (and sum through collection counts) is shared; and the FeatureReferences structs are only initialized once.

It cuts the version checks from 7 to 5; and the cache initialization to 2x Context, 1x Request, 1x Response, so down 2.

Pre

Post

The early init of the FormFeature triggered the access of the HttpRequest and caused initalization; so I had to move that to be on demand - so it also resolves:

Fixes #677 "FormFeature allocates when unused"
Fixes #880 "Don't allocate the FormFeature eagerly per request"

Also

Sealed and made concrete the DefaultHttpRequest and DefaultHttpResponse class/references for devirtualization and made their initialization/uninitialization simpler.

Someone can always inherit from HttpContext/HttpRequest/HttpResponse if they want a non-Default.

However it doesn't preclude alternative uses. As an example, reimplemented the PooledHttpContext sample by composing with DefaultHttpContext rather than via inheritance.

/cc @davidfowl @muratg @vancem @Tratcher @HaoK

@@ -8,5 +8,65 @@
"TypeId": "public class Microsoft.AspNetCore.Http.HttpContextFactory : Microsoft.AspNetCore.Http.IHttpContextFactory",
"MemberId": "public .ctor(Microsoft.Extensions.ObjectPool.ObjectPoolProvider poolProvider, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Http.Features.FormOptions> formOptions, Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Http.DefaultHttpContext : Microsoft.AspNetCore.Http.HttpContext",
Copy link
Member

@davidfowl davidfowl Nov 9, 2017

Choose a reason for hiding this comment

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

@benaadams We can't make breaking changes in a minor update.

@davidfowl
Copy link
Member

@benaadams This introduces breaking changes. Do you have something that doesn't break APIs?

@davidfowl
Copy link
Member

@benaadams Closing this out. I think we need to find an approach that doesn't break things. Maybe we write a different HttpContext implementation that does this instead of changing the default.

@benaadams
Copy link
Contributor Author

Non-breaking #999

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.

4 participants