Skip to content

Use Math to get min scale and max scale in Viewbox.ComputeScaleFactor - #3463

Closed
h82258652 wants to merge 2 commits into
dotnet:mainfrom
h82258652:useMathGetMinAndMax
Closed

h82258652 wants to merge 2 commits into
dotnet:mainfrom
h82258652:useMathGetMinAndMax

Conversation

@h82258652

Copy link
Copy Markdown

No description provided.

@h82258652
h82258652 requested a review from a team as a code owner September 7, 2020 04:50
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Sep 7, 2020
@ghost
ghost requested review from SamBent, fabiant3 and ryalanms September 7, 2020 04:50
@miloush

miloush commented Sep 7, 2020

Copy link
Copy Markdown
Contributor

What is the performance impact of this change?

@h82258652

Copy link
Copy Markdown
Author

@miloush Due to the method call, the performance is a little worse than before, but the code is clearer. I don't know should I pr this. If we need to consider the performance, there are lots of Math calls that can be replaced.

@fabiant3

fabiant3 commented Sep 8, 2020

Copy link
Copy Markdown
Contributor

It's unfortunate but we don't have automated perf tests running on WPF NET5. This is critical path code, so I wouldn't spend time on this PR at the moment.

@miloush

miloush commented Sep 9, 2020

Copy link
Copy Markdown
Contributor

@h82258652 That's not even true in general, the method call might get optimized away. It depends on the compiler, jitter, platform, where the values come from, their data types etc.

Being able to state either "under conditions X the performance improvement is Y and every WPF app hits this line 100 times at start-up" or "we get more readable/consistent code for the performance/size cost of X and the code is rarely ever hit" helps people to make an informed decision on whether the change is worth the effort and risk.

@gfoidl

gfoidl commented Sep 16, 2020

Copy link
Copy Markdown
Member

Due to the method call, the performance is a little worse than before

FYI with dotnet/runtime#33851 Math.Min and Math.Max will be inlined.
It still may be a bit slower due the handling of NaNs and other edge-cases, which the simple comparison doesn't have. Depending on the CPU the branch-predictor may do a good job, so this handling of the edge-cases may not show up in perf-numbers.
I'd go with the cleaner code as this PR suggests.

@ryalanms ryalanms added the Performance Performance related issue label Jan 7, 2021
Base automatically changed from master to main March 17, 2021 17:38
@pchaurasia14 pchaurasia14 added the Community Contribution A label for all community Contributions label Jul 20, 2022
@ghost ghost assigned h82258652 Jul 20, 2022
@rchauhan18

Copy link
Copy Markdown
Contributor

I performed a perf test and it shows that using Math.Max/Math.Min is 4-5 times slower then the default. Here are the results:

image

If we take this PR now, the only output we get is a clean code at the cost of reduced performance. As such, we are closing this PR until the time there is a change in underlying functions which has atleast same or comparable performance.

@miloush

miloush commented Aug 17, 2023

Copy link
Copy Markdown
Contributor

Not mentioning the fact that it changes behaviour. If scaleX is NaN and scaleY is not, the result is currently scaleY, but with the proposed change it would be NaN.

@rchauhan18 rchauhan18 closed this Aug 17, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions Performance Performance related issue PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants