-
Notifications
You must be signed in to change notification settings - Fork 183
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
Cache FakeOptions constructor to improve performance #1466
Comments
Actually, I may have come up with a nice way to not construct the |
Well done, @blairconrad! Looks like a good improvement. |
Yes, it would be even better, I guess. |
Rerunning with 27.04% to 2.93%. Not bad. Thanks for the push, @thomaslevesque. I'll work on avoiding construction next. |
I was originally thinking we could avoid creating the object when users don't use creation method that specifies an option builder action, but we also have to make sure there's no |
Using BenchmarkMockNet to test constructors. With FakeItEasy 4.8.1
Using BenchmarkMockNet to test constructors. With a build including this issue:
Take with grain of salt. The computer was doing other things. But still, I'm pleased with the change. |
It certainly looks much better! I think I'll do some profiling tonight, to see if there's more to be gained. |
I'm sure there's some fat to trim. |
This change has been released in FakeItEasy 5.0.0. |
For a lark, I profiled creating 100,000 instances of a small interface (after warming up FakeItEasy by faking a different interface). Using dotTrace, I found that
DefaultFakeAndDummyManager.BuildProxyOptions
was a hotspot. So I started caching the constructor by type of Fake and found this difference:BuildProxyOptions
drops from 19.10% of the total time to 9.95%. Or if you prefer the diff view:Of course we're trading away some storage space. If we end up faking many different types once, this is a bad tradeoff, but if types are faked more than once, it may be a benefit.
Also, in many cases we don't even need a
FakeOptions
object. I can explore dropping the construction step as well.The text was updated successfully, but these errors were encountered: