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

Improve Dummy and Fake constructor caching #1359

Closed
blairconrad opened this issue May 15, 2018 · 2 comments
Closed

Improve Dummy and Fake constructor caching #1359

blairconrad opened this issue May 15, 2018 · 2 comments
Assignees
Milestone

Comments

@blairconrad
Copy link
Member

Even though we cache (keying off the type) each ResolveStrategy used to successfully create a Dummy, we still may be doing significant work on subsequent calls. If the ResolveByCreatingFakeStrategy or ResolveByInstantiatingClassUsingDummyValuesAsConstructorArgumentsStrategy are cached, invoking them will still require re-enumerating the constructors and possibly creating many extra constructor arguments. We could consider adding additional caching so we don't have to redo all this work.

Ideas:

  1. have each resolver replaced by a "resolver source" that emits a list of resolvers based on the type being created. Most of these would just return the existing single resolver, but the "constructor-enumerating" resolvers could emit one resolver per constructor until one worked, and that one would then be cached. This is a little awkward for most of the resolvers, and is quite tricky for the ResolveByCreatingFakeStrategy, since it currently just calls to IFakeObjectCreator.TryCreateFakeObject, which handles the constructors internally.
  2. Add constructor (or argument type) caching to ResolveByInstantiatingClassUsingDummyValuesAsConstructorArgumentsStrategy and FakeObjectCreator. This would keep the shape of all the other ResolveStrategys as is, and would have the benefit that the cached constructor (or argument types) would aid in Fake creation even when the Fake isn't being created to be a Dummy.

(From #1347)

@blairconrad
Copy link
Member Author

We went with option 2, adding caching to ResolveByInstantiatingClassUsingDummyValuesAsConstructorArgumentsStrategy and FakeObjectCreator.

@blairconrad blairconrad added this to the vNext milestone Jun 22, 2018
@blairconrad
Copy link
Member Author

This change has been released as part of FakeItEasy 4.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant