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

Streamlining feature cache and object re-initialiation code paths #516

Merged
merged 6 commits into from
Dec 31, 2015

Conversation

lodejard
Copy link
Contributor

Shouldn't increase object size, but does improve maintainability

@davidfowl
Copy link
Member

/cc @benaadams

@lodejard
Copy link
Contributor Author

/cc @DamianEdwards also

Outside of pooling this also has the benefit of making DefaultHttpContext more useful as a base class. By overriding the Initialize methods an app author can subclass the request/response/etc companion objects, otherwise you have no control over those associated objects.

{
}

protected override HttpRequest InitializeHttpRequest()
Copy link
Member

Choose a reason for hiding this comment

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

You need to override all of methods in order to properly pool right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a policy choice, really - the ConnectionInfo/WebSocket objects might be used infrequently enough it could be could be more efficient to let them be garbage collected. But yes, you would override all child object management methods to take full control

Adding comment about reason for public field
@@ -274,6 +271,7 @@ private static void TestFeatureProperties(object value, IFeatureCollection featu
{
if (property.Name.Contains("Feature"))
{
Console.WriteLine($"{value.GetType().Name} {property.Name}");
Copy link
Member

Choose a reason for hiding this comment

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

Remove this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

‼️

@davidfowl
Copy link
Member

Looks good to me :shipit: . @Tratcher might want to comment

{
var type = value.GetType();

var fields = type
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't verify anything anymore because the object layout has changed. The only field it will find is FeatureReferences<FeatureInterfaces> _features;.

Copy link
Member

Choose a reason for hiding this comment

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

Unless it manages to unroll the nested structs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, a unit test that reflects over the private implementation details seemed a little :suspect: to me in the first place, but comparing the nested struct to default(T) could certainly be done...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test updated to assert _features field state is reset to default(T). Though I'm still highly suspicious of the practice.

@Tratcher
Copy link
Member

shrug

@lodejard
Copy link
Contributor Author

What's the emoji for shrug? 😐? 😶? 🙈?

:)

@pranavkm
Copy link
Contributor

¯\_(ツ)_/¯

TestCachedFeaturesAreSet(context.WebSockets, features);
}

void TestCachedFeaturesAreSet(object value, IFeatureCollection features)
Copy link
Member

Choose a reason for hiding this comment

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

TestCachedFeaturesAreSet needs to be updated 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.

That one is already getting the property, and getting the interface type, and asserting they are the same. Isn't using reflection on fields to verify a private has been changed highly unusual? I can add unit test over FeatureReferences is that verify it's calling through only once, but doing the testing of that class indirectly seems wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was trying to test if the cached (private var) was correct for the current and any future additions so act as a regression safety test; even found a few instances where it wasn't actually being saved to the private var with the test. (So the cache wasn't caching - though it publicly worked)

@benaadams
Copy link
Contributor

LGTM, and does look a lot better

@davidfowl
Copy link
Member

:shipit:

@benaadams
Copy link
Contributor

Hmm, related #522 though not a blocker; thought I could work round this issue for Frame but the call stack runs through here.

Current flow
Middleware -> httpContext.Request.Path -> DefaultHttpRequest.get_Path -> GetAndCache<T> -> FeatureCollectionExtenstions.Get<T> -> (TFeature) features[typeof (TFeature)] -> Frame.FastFeaturesGet(Type)

@halter73 halter73 merged commit c95d816 into dev Dec 31, 2015
Collection.Set(feature);
if (!cleared)
{
Cache = default(TCache);
Copy link
Contributor

Choose a reason for hiding this comment

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

Bit late; but not sure about this if statement? What's it doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be #524 ?

@JunTaoLuo JunTaoLuo deleted the lodejard/featurereferences branch January 6, 2017 22:02
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.

7 participants