-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 RGB Min Max evaluation performance by using 2 or 3 comparison… #50622
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a0fabe
Improve RGB Min Max evaluation performance by using 2 or 3 comparison…
L2 59d5387
Conform trailing braces to .NET style guide
L2 8341fe2
Add missing functional test cases for MinMaxRgb
L2 03644b6
Use ternary conditional operator and out var initialization
L2 5c109b7
Simplify by removing nested conditionals
L2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be simplified to instead be:
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.
Thanks @stephentoub , I ran the perf_color microbenchmarks against 1) before this PR changeset, 2) the current PR's changeset, 3) proposed simplification
**.NET6 Before VS .NET6 with current PR changeset: Run1**
summary: better: 3, geomean: 1.151 total diff: 3No Slower results for the provided threshold = 2% and noise filter = 25ns.
**.NET6 Before VS .NET6 with current PR changeset: Run2**
summary: better: 3, geomean: 1.208 total diff: 3No Slower results for the provided threshold = 2% and noise filter = 25ns.
**.NET6 Before VS .NET6 with current PR changeset: Run3**
summary: better: 3, geomean: 1.189 total diff: 3No Slower results for the provided threshold = 2% and noise filter = 25ns.
**.NET6 Before VS .NET6 with proposed simplification: Run1**
summary: better: 2, geomean: 1.123 total diff: 2No Slower results for the provided threshold = 2% and noise filter = 25ns.
**.NET6 Before VS .NET6 with proposed simplification: Run2**
summary: better: 3, geomean: 1.135 total diff: 3No Slower results for the provided threshold = 2% and noise filter = 25ns.
**.NET6 Before VS .NET6 with proposed simplification: Run3**
summary: better: 2, geomean: 1.132 worse: 1, geomean: 1.050 total diff: 3Some of the benchmarks seem to get a bit slower on average after the simplification. I think what is happening may be two causes:
I will follow yours and @safern 's recommendation on which to keep. Thanks again.
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.
I didn't look at the disassembly but there might be an aliasing complication also, if the JIT compiler has to account for the possibility that
min
andmax
refer to the same location. Although perhaps it can disprove that after inlining.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.
I actually see them get faster on my machine. Regardless, though, I'd rather keep the code smaller, especially with it triplicated due to the aggressive inlining.
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.
One more possible improvement - using local valiables instead of
out
parameters: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.
Sounds good @stephentoub , I've updated it with the requested changes. (I'm not sure how crediting works in this project as this is my second pull request, so I've added your username to the commit details as the originator of the simplification).
Thanks @hypeartist, I'm wondering if these local variables will be eliminated due to inlining, so performance will be about the same?
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.
Thanks, but not necessary... I comment on a lot of PRs :)
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.
Yes, e.g.
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIAYACY8gOgCUBXAOwwEt8YLAMIR8AB14AbGFADKMgG68wMXAG4aNYgGYmpBkIYBvGgzNNdvHgwCy5ABRWMDKGgZOGAczcfgASmNTc2CbKxtsBDZPYAcIDmcPfCs3OITrfAi3Vy83fw1qYODiAHYGDIQGODKrfOCAXyCzRot3axtSR2tsj29W539AgsKzUK5wyOiO1L7qrhT4mfKst1685qLS8srZ2vMGoaaDhgBtGxgMAAsIABMASXFJezPLm/uxSQB5MT4ILlwWACCnk8sFwuF4Chgty4kisVk8fgAus0xFAIdgMDAmOQkEwULYwhEojF7NNEskGGT0pkZt1rL1fH5miYjsFeAAzBj2KAMAB8XiZrPMLOGwy2AF4XLtReYklwGJLPNLCvsZTBJLgYOthdqxREFV5lTK5QaoEa9rr3Jz7MA+WUIoKZSKZbL9ZLgOazKrRerNVaubaADyzR2i50u2YGj2W71e5rNU7nK53B5PJOvB5fH5/QHA0HgyHQ2FceFIlFohQYrHMXHEfGjcbEqYLclzSkt6kIHxdbvOBnWfzMy2tgAyEDAbnKY7Anv93LtCMt4ZdU/HptnwTl04NSpjlt9WqFZmXxoi28VG9lVnPUr31GH1tt/NXYFDwxPopfUdnscKB7nQazNOb6FB+YrXmu7o/poR72hUkovrOJoIRBM7NPsdRAA===