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

Propagate Form and ResponseCookie init options #675

Closed
wants to merge 1 commit into from

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented Jul 22, 2016

Also has nice side effect of allowing lazier load of the two features

Before
pre-allocations

After
post-allocations

DefaultHttpContext increases by 16 bytes (120bytes->136bytes)
But it drops ResponseCookiesFeature at 56 bytes and FormFeature at 48 bytes

So overall 88 bytes and 2 allocations down per request or 83MB per 1M requests

Resolves #676
Resolves #677

/cc @Tratcher

@muratg
Copy link

muratg commented Jul 25, 2016

Putting in 1.1 for investigation

public DefaultHttpContext()
: this(new FeatureCollection())
{
Features.Set<IHttpRequestFeature>(new HttpRequestFeature());
Features.Set<IHttpResponseFeature>(new HttpResponseFeature());
}

public DefaultHttpContext(IFeatureCollection features)
public DefaultHttpContext(IFeatureCollection features, ObjectPool<StringBuilder> builderPool = null, FormOptions formOptions = null)
Copy link
Member

Choose a reason for hiding this comment

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

Split this into two constructors

@Tratcher Tratcher assigned pakrym and unassigned Tratcher Aug 18, 2016
@benaadams benaadams force-pushed the propagate-feature-init branch 3 times, most recently from e3c48bd to 102ee28 Compare August 21, 2016 11:05
@benaadams
Copy link
Contributor Author

benaadams commented Aug 21, 2016

@Tratcher @pakrym @davidfowl updated with currying, which makes creation is less messy and adds 16 more bytes; so only 72 bytes saved (72MB per 1M req) 😞

Still breaks the feature chaining @Tratcher referenced, to make it work this

var feature = context.Features.Get<IResponseCookiesFeature>() ?? 
    new ResponseCookiesFeature(context.Features);

Would need to change to

var feature = context.Response.Cookies != null ?
    context.Features.Get<IResponseCookiesFeature>() :
    new ResponseCookiesFeature(context.Features);

Which isn't great... but if you are in an auth'd flow security ResponseCookies aren't being set on every request if you have a good RequestCookie?

Also has side effect of allowing lazier load of the two features
@benaadams benaadams force-pushed the propagate-feature-init branch from 102ee28 to 7243252 Compare August 21, 2016 11:19
@benaadams
Copy link
Contributor Author

@rynowak don't think this causes the feature collection to become dirty as is just regular flow construction? (its discards should have been resolved in #623)

@pakrym
Copy link
Contributor

pakrym commented Sep 30, 2016

Closing, even considering allocation gains we cant break feature chaining pattern.

@pakrym pakrym closed this Sep 30, 2016
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.

6 participants