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 via GetImplementingMethod: https://github.com/moq/moq4/blob/9fcf8a0c214dc6cdcaee813b0623e7c3f121924c/src/Moq/Extensions.cs
which 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.
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
GetInterfaceMapviaGetImplementingMethod: 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
GetInterfaceMapthe 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
GetInterfaceMapcalls in the extension method itself but this feels unclean.