Reduce Revision check calls via interface#623
Conversation
|
😻 |
|
Not to derail too much, but do we have a feel for how much benefit we're really getting from using this pattern instead of just calling |
If you only access a feature once per request not much; but if you access it more than once it should be significant e.g. the plaintext benchmark accesses However instead of doing if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal))
{
httpContext.Response.StatusCode = 200;
httpContext.Response.ContentType = "text/plain";
httpContext.Response.Headers["Content-Length"] = "13";
return httpContext.Response.Body.WriteAsync(_helloWorldPayload, 0, _helloWorldPayload.Length);
}It could do if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal))
{
var response = httpContext.Response;
response.StatusCode = 200;
response.ContentType = "text/plain";
response.Headers["Content-Length"] = "13";
return response.Body.WriteAsync(_helloWorldPayload, 0, _helloWorldPayload.Length);
}To access it only once; but users probably won't do that |
|
Maybe we could make the cost of the extra lookups even lower? 😀 #617 The hope is that the cost of abstraction is low and that doing optimizations like using the feature directly aren't super beneficial. |
|
I was trying to see if it could be a compile/jit time lookup though it would only work with generics not |
| { | ||
| var cleared = false; | ||
| if (Revision != Collection.Revision) | ||
| if (Revision == 0) |
There was a problem hiding this comment.
We could also check cached == null here, but this might do enough already. And if we're worried about inlinability being more thorough might be bad (code size)
There was a problem hiding this comment.
If cached == null it couldn't update the revision count as it may have changed and other cached features may be invalid; which would mean on second use it would have to clear the cache.
There was a problem hiding this comment.
This makes some assumptions about the implementation of Collection.Revision and the initial value. E.g. WebListener's Revision count starts at 0 so this code will keep executing.
There was a problem hiding this comment.
Resolved, but 3 nested ifs :(
There was a problem hiding this comment.
Hmm, but this will go wrong if revision has changed
There was a problem hiding this comment.
This code could do with some comments. If we had fxcop it would probably complain about the cyclomatic complexity
There was a problem hiding this comment.
You'd be surprised how high that complicity limit is.
|
OSX is grumpy on restore |
|
|
|
Rebased and merged. |




Can cache the first lookup