Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize a few aspects of the interception process #546

Merged
merged 6 commits into from
Dec 6, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Dec 6, 2017

No description provided.

When `argumentMatchers` is constructed, `out` parameters are filtered
out. This makes things harder (and slower) than necessary. Instead of
removing `out` parameters, match them with the dummy `AnyMatcher`.
Make both `Method` and `Arguments` non-virtual properties of the base
class. This makes querying those properties faster because delegation
to DynamicProxy is avoided.

Letting the base class handle `Arguments` means that deriving classes
must be explicitly notified about an invocation's end, so that they
can write back modified arguments to by-ref parameters. That is what
the three new `Return` methods are for.

Having Moq explicitly end an invocation makes it possible for Dynamic-
Proxy's `Invocation` subclass to "detach" itself from the underlying
`IInvocation` when is no longer needed, so it can be GC'ed earlier.
`SetupCollection.FindMatchFor(Invocation)`: Add a fast path for the
case when there are no setups at all.

`InvokeBase`: Rewrite the convoluted condition that checks whether the
base method can / should be called. Problems with the current checks:

 1. It's almost impossible to make sense of.

 2. The least expensive checks (such as checking `mock.CallBase` or
    `invocation.Method.IsAbstract`) happen last.

 3. Many checks are unnecessary because they never evaluate to true.
    For example, `object` methods have already been dealt with in
    `HandleWellKnownMethods`; event attach / detach methods have been
    dealt with in `RecordInvocation`.
These two invocation aspect handlers essentially have the same pur-
pose: ending an invocation and producing a return value (if required).
Strict mocks require that setups explicitly provide a return value.
This check is unnecessary for void method setups. Let's therefore move
it into `MethodCallReturn`.
@stakx stakx changed the title Speed up invocation interception a little Optimize a few aspects of the interception process Dec 6, 2017
@stakx stakx merged commit 0ce473a into devlooped:develop Dec 6, 2017
@stakx stakx deleted the optimization branch December 6, 2017 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant