-
-
Notifications
You must be signed in to change notification settings - Fork 546
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 performance of AllBeEquivalentTo #920
Improve performance of AllBeEquivalentTo #920
Conversation
Improves algorithmic complexity from O(n^2) to O(n)
Out of curiosity, Did you measure the wall time improvement of this PR for the new test? |
What does "wall time" mean? :-) |
Wall time is just another word for the runtime measured in e.g. seconds instead of algorithmic complexity. |
I tried to measure the time for 10000 items but gave up after a few minutes :-). Even for a few hundreds of items times were in the order of minutes. With strict ordering and 100 000 items, I have around 13s. EDIT: For the record(N=500):
|
FYI: Last commit(502977c) fixed issue unrelated to the topic of the PR. When I set strict ordering for the top-level collection exception, the message for existing test case changed. The reason was the discrepancy between Please review that particular scenario, I am not sure I understand the code deeply enough. |
I found out during profiling that repeated call to this method was taking up to 10% of the execution time.
…quivalencyValidator`
I'm loosing track of what each PR is supposed to. Normally, if a PR consists of multiple commits, I assume you have carefully squashed individual changes into a couple of well-focused commits. We also merge these PRs by keeping all commits. So please either separate unrelated changes into separate PRs or make sure you squash commits that change stuff in previous commits into the same one. I regularly use fixup commits and/or amend existing commits. |
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.
Only minor comments. See legend on what those emojis mean
Src/FluentAssertions/Equivalency/EnumerableEquivalencyValidator.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/EnumerableEquivalencyValidator.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/EnumerableEquivalencyValidator.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/EnumerableEquivalencyValidator.cs
Outdated
Show resolved
Hide resolved
First of all thanks for mentioning fixup commits, I had no idea such a thing exists. Regarding the topic of this PR. Every commit but one is directly tackling performance problem as stated in the PR title. The one outstanding commit (502977c) was necessary (at least at the time of writing) because after I introduced the Now we need to decide how to proceed. Possible scenarios: A) After my explanation, you understand the scope of the feature and you merge it with squash. In either case from now on, for new PR's I will prepare my branches
|
Absolutely. My intention was just to explain my preference for this repo. |
Attempt to fix #914.
There are (at least) two bottlenecks:
AllBeEquivalentTo
created a collection of items matching the subject's length, and then used loose ordering which results in O(n^2) complexity. Change to strict ordering is necessary to have hope for any kind of reasonable performance.EnumerableEquivalencyValidator
after say 10 failures.OrderingRules.IsOrderingStrictFor(context)
inEnumerableEquivalencyValidator.AssertElementGraphEquivalency
before the loop. During profiling, it stands out as an easy-fix with the execution time around 8-10% spent in this method.I checked that after those three issues there are no more outstanding hot spots. Execution time is split among some
CanHandle
methods, creating objects likeEquivalencyValidationContext
and so on.Any ideas are warmly welcomed.