Skip to content
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

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

Closed
wants to merge 2 commits into from

Conversation

h82258652
Copy link

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 fabiant3, ryalanms and SamBent September 7, 2020 04:50
@miloush
Copy link
Contributor

miloush commented Sep 7, 2020

What is the performance impact of this change?

@h82258652
Copy link
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
Copy link
Member

fabiant3 commented Sep 8, 2020

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
Copy link
Contributor

miloush commented Sep 9, 2020

@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
Copy link
Member

gfoidl commented Sep 16, 2020

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
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
Copy link
Contributor

miloush commented Aug 17, 2023

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.

None yet

7 participants