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

Replace Mock.Of code with 10x faster equivalent #598

Merged
merged 8 commits into from
Mar 1, 2018

Conversation

informatorius
Copy link
Contributor

#547

PR not finished yet ...

@informatorius
Copy link
Contributor Author

Fixing ...
What about the benchmarks you did, should I include them somehow?
Or is this done with #388

@stakx
Copy link
Contributor

stakx commented Feb 28, 2018

The time required to create a mock depends on the complexity of the type you want to mock. So including one single benchmark for one single mocked type wouldn't really give the full picture. All I wanted to see with that benchmark is an approximate speed difference (order of magnitude).

I'll review your PR a little later!

Copy link
Contributor

@stakx stakx left a comment

Choose a reason for hiding this comment

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

Looking good. I would appreciate it (but I won't insist on it) if you could rephrase the code comment and changelog entry a bit.

Thanks for you work so far! 👍

CHANGELOG.md Outdated
@@ -11,6 +11,9 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1

* Add `ISetupSequentialResult<TResult>.Returns` method overload that support delegate for deferred results (@snrnats, #594)

#### Changed

* Changed `Mock.Of<T>()` implementation to use much faster simple approach (@informatorius, #547)
Copy link
Contributor

Choose a reason for hiding this comment

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

In principle, this is a perfectly fine changelog entry. But may I humbly suggest that you shorten & rephrase it to be even more relevant from the user's perspective? For example:

  • Speed up Mock.Of<T>() by approx. one order of magnitude (...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh btw., please replace #547 (issue) with #598 (this PR).

return Mocks.CreateMockQuery<T>().First<T>();
//Disabled because of bad performance
//return Mocks.CreateMockQuery<T>().First<T>();
//and replaced by equivalent which is more than 10 times faster currently
Copy link
Contributor

@stakx stakx Feb 28, 2018

Choose a reason for hiding this comment

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

Hmm, IMHO using the word "bad" isn't quite fair. I totally agree that the current implementation has worse performance than your new one; but does that make it bad?

I would've chosen a more neutral wording that avoids negative judgement; for example:

// This method was originally implemented as follows:
//
//     return Mocks.CreateMockQuery<T>().First<T>();
//
// which involved a lot of avoidable `IQueryable` query provider overhead and
// lambda compilation. What it really boils down to is this (much faster) code:
...

CHANGELOG.md Outdated
@@ -11,6 +11,9 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1

* Add `ISetupSequentialResult<TResult>.Returns` method overload that support delegate for deferred results (@snrnats, #594)

#### Changed

* Changed `Mock.Of<T>()` implementation to use much faster simple approach (@informatorius, #547)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add one more blank line after this one.

@informatorius
Copy link
Contributor Author

Done! Thanks for your perfect feedback.

@stakx stakx merged commit 1169f5c into devlooped:master Mar 1, 2018
@stakx
Copy link
Contributor

stakx commented Mar 1, 2018

Thank you for contributing this much faster reimplementation of Mock.Of<T>()! 👍

@stakx
Copy link
Contributor

stakx commented Jun 9, 2018

@informatorius - I just pushed Moq 4.8.3 to NuGet, which includes your changes. Sorry it's taken so long.

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

2 participants