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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 Auto properties on large record types causes severe performance degradation #1432
Comments
Hi @putnap, AutoFixture currently looks at the list of constructors takes the least demanding public constructor and uses it to initialize the data, then it looks at your other members and assumes that since you exposed a public setter you need it initialized from outside the constructor, so it does just that. This is why you're observing the behavior that you described. I'm currently working on an API for easier customization of record-like structures (customizing constructor parameters, selecting constructors, etc), but it's still in early development. // Example record
record Customer(string FirstName, string LastName);
// Equivalent class generated in IL
class Customer
{
public Customer(string FirstName, string LastName)
{
this.FirstName = FirstName;
this.LastName = LastName;
}
public string FirstName { get; set; }
public string FirstName { get; set; }
} |
Thanks for a quick reply! I guess there are two topics - customizing via record constructors feature and performance issues. Also, I believe that class you mention is not equivalent, since record types are immutable by default and generated properties don't have public setters, only public string FirstName { get; init; }
public string LastName { get; init; } And I would like some peace of mind that my ICustomization with |
About the This said I don't think the customization in your sample is doing anything else than ignoring all properties. Here is a gist that shows an example, how to ignore specifically those properties that are init only and constructor initialized Expand for IL examples
|
Thanks, I'll use the workaround you suggested, seems to work! |
Describe the Bug
It looks like record type with constructor is a cause for performance degradation, which can be worked around by using
OmitAutoProperties()
or by customizing each property usingWithout()
.Scenario
In our project we are using rather wide and deeply nested structure as our main DTO and we are using xUnit, AutoFixture and Moq to write our tests. We have about 120 unit tests a lot of them create this large DTO using
AutoMoqDataAttribute
. The suite of tests in our CI consistently run for around 25 minutes, which is horrible.I started exploring why that is and I had a strong suspicion that our large DTO is causing this, because tests without it completed very quickly, I tried then tried reducing the amount of auto properties on the structure to only header values and tests started to run quick, but I still had all the values automatically generated. I was happy I found a workaround that helps us in significant way, but at the same time I am concerned why this is happening.
I've created a repository which has minimum setup needed to reproduce the issue and basic explanation is this:
OmitAutoProperties()
orWithout()
don't work on constructors for record typesI've created a customization that checks if property is record type property by assuming that it has
CompilerGeneratedAttribute
.Expected Behavior
By using
OmitAutoProperties()
orWithout()
it's expected that record type will not have a value automatically set.Tasks
Immediate question
I am fine having this workaround for now, but maybe someone can confirm that it won't cause any other issues for running tests?
Thanks!
The text was updated successfully, but these errors were encountered: