Giter Site home page Giter Site logo

Comments (5)

peterder72 avatar peterder72 commented on July 19, 2024 1

@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.

stakx avatar stakx commented on July 19, 2024

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.

stakx avatar stakx commented on July 19, 2024

@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.

peterder72 avatar peterder72 commented on July 19, 2024

@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.

stakx avatar stakx commented on July 19, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.