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
Performance optimization: focusing on allocation reduction #2158
Conversation
@dotnet-policy-service agree |
For detailed analysis, read Frugal Cafe postings 60,61,62: https://frugalcafe.beehiiv.com/p/fc60-fluentvalidation-engineered-not-recommended |
Hello, Thank you for the suggestion. There are currently 13 tests failing introduced by these changes. Please resolve all test failures - once this is done I'll then review the PR. Thanks |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @paulomorgado glad you managed to get the failures to show up locally. I've added some comments to show where the bugs are, as well as some other changes I'd like to see. Thanks!
…validation failure
I had some time today to implement the necessary fixes to the PR. I have made the following changes:
This has now been merged with these changes. Thanks for contributing. |
return true; | ||
} | ||
|
||
if (value is string s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't these three also change the behavior of the switch expression above.
Line 35 says: "When the value is a string and is empty, return true, otherwise return the EqualityComparer on line 42/49"
This now says: "When the value is a string, return if the string is empty"
The same for the other 2 ICollection and IEnumerable
To maintain same behavior I suggest
if (value is string s && string.IsNullOrWhiteSpace(s))
return true;
\\etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billrob yes you're right - I didn't catch that. I've pushed out an 11.8.1 release with a fix.
Even in the non failure case, FluentValidation has too many allocations. For the Customer example, single validation has 44 allocations, 2,172 bytes in total. This can be reduced to 10 allocations (including the Customer object), 604 bytes, 72% reduction.