-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Performance with large interfaces #1128
Comments
Your use case might have revealed a potential performance problem, but having an interface with thousands of methods isn't exactly the most common use case (how on Earth would you ever implement that monstrosity by hand?!) so I don't think we should rush a cache into Moq without taking a closer look. A cache should be among the last options to consider, not the first. IIRC, Can you please provide a runnable repro? |
Can we revisit this? We're seeing the exact same issue. For us, a few tests spend 99% of the time in just the Moq. This means we had to disable a few performance tests. Here is a quick PerfView trace of the runtime:
|
This comment was marked as outdated.
This comment was marked as outdated.
Scratch my above comment, I only noticed just now that you reposted this in a new issue. Let's continue there. |
When upgrading from Moq 4.10.0 to 4.15.2 and mocking an interface with thousands of methods the cost of creating the runtime mock is significant which slows down test runs. Yes I know that god objects are a code smell.... :)
The most expensive call is
GetInterfaceMap
viaGetImplementingMethod
: https://github.com/moq/moq4/blob/9fcf8a0c214dc6cdcaee813b0623e7c3f121924c/src/Moq/Extensions.cswhich is called repeatedly.
When creating a mock of my type the test execution time for a single test is around 5 seconds.
After adding a simple fix to cache the results of
GetInterfaceMap
the execution time drops to milliseconds.Would adding a cache for the results of GetInterfaceMap be accepted? As far as I can fathom the results of the call cannot change given that the input type is already baked.
The method is an extension method and has no access to any sort of Moq internals so I'm stumped on where to put a cache that is harmonious with the the design of Moq. I have fork that just caches the
GetInterfaceMap
calls in the extension method itself but this feels unclean.The text was updated successfully, but these errors were encountered: