Comments (5)
@stakx I haven't implemented any caching mechanisms myself, I just fixed the way expressions are compiled for It.Is, see here. This already fixes the biggest performance drop that causes times of 1m for verification
from moq4.
There was another issue a few years ago about caching expression trees to improve performance; IIRC, that was one of the reasons that led to the ExpressionCompiler
extension point. You can set ExpressionCompiler.Instance
to an instance that caches already compiled expression trees, and Moq will then use that.
IIRC, the reason why the cache wasn't added directly to the default implementation was that there was some uncertainty about how to unambiguously recognize already compiled expression trees and map them to a cached delegate (i.e. how to prevent false positives in the cache lookup).
I suppose if the caching logic is reliable and not overly complex, then that previous decision could be revisited. What does your caching implementation look like?
from moq4.
@peterder72, I see. My apologies for the misunderstanding. Looks like a reasonable change to make. 👍
The only thing I'm left wondering is whether compiling the expression tree once, ahead-of-time instead of once per invocation of the matcher could possibly affect how & when captured variables get evaluated. I don't think so, but it may be worth verifying.
from moq4.
@stakx I was also thinking about the same thing, but I can't see anything that can become an issue here, since nothing is captured in the scope of It.Is, all references come from the caller. If you can think of how it could go wrong so that I can put it under test, let me know, I'll also give it a think for now
from moq4.
@peterder72, I was mostly thinking about things like:
var obj = ...;
... It.Is(x => x == obj) ...
// ^^^
// when / how often does this captured variable get evaluated?
But on second thought, even that shouldn't be a problem, since compilation in all probability does not perform any kind of partial evaluation.
I can't think of any other reasons why the change shouldn't be made. Looks good to me.
(Be advised that I am not committing anything to this repo for the time being, due to the recent SponsorLink disaster, so I likely won't be the one merging your PR if you decide to submit one.)
from moq4.
Related Issues (20)
- Privacy issues with SponsorLink, starting from version 4.20 HOT 393
- SponsorLink and supporting OSS more broadly HOT 727
- Strange System.UnauthorizedAccessException during build using latest version HOT 4
- SponsorLink is now OSS too and no longer bundled HOT 87
- Trouble to unit test a lambda expression with Moq HOT 1
- Default value ILookup<> in loose mode is `null` HOT 1
- Using 'Verify' and 'It.Is<>' with a method call inside cases the same verify the run for all invocations HOT 6
- Permanently delete all data from SponsorLink's database that has been collected during builds that included Moq (notably any version 4.20.*) HOT 18
- Stop using Moq as a guinea pig to get feedback on and develop SponsorLink HOT 105
- Support Static Abstract property HOT 1
- Community Involvement HOT 5
- Change log is not updated since version 4.18.4 HOT 3
- Mocking Blobclient.DownloadContentAsync() HOT 3
- Poll on SponsorLink HOT 1
- Should allow null references as constructor parameters. HOT 1
- Replacement for Moq.MethodCallReturns'2 HOT 3
- The public API is still missing nullable reference type annotations HOT 1
- a minor changes to improve the readability HOT 2
- [Feature Request] Make it possible to moq concrete classes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moq4.