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 span for LengthConverter #8622

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jan 2, 2024

Description

Use span for LengthConverter and other similar places. I also introduced the internal struct PixelUnit to share some of the logic.

I found that LengthConverter.FromString can be called a lot on startup (~3000 times in a sample app).

Benchmark
Method s Mean Error StdDev Ratio Gen0 Code Size Allocated Alloc Ratio
Old 12 37.447 ns 0.0442 ns 0.0369 ns 1.00 - 1,146 B - NA
New 12 33.244 ns 0.0190 ns 0.0148 ns 0.89 - 670 B - NA
Old 12cm 39.023 ns 0.0914 ns 0.0810 ns 1.00 0.0019 1,176 B 32 B 1.00
New 12cm 33.253 ns 0.0478 ns 0.0424 ns 0.85 - 714 B - 0.00
Old 12CM 43.755 ns 0.1675 ns 0.1567 ns 1.00 0.0038 1,158 B 64 B 1.00
New 12CM 33.792 ns 0.0985 ns 0.0921 ns 0.77 - 714 B - 0.00
Old 12in 36.953 ns 0.0672 ns 0.0561 ns 1.00 0.0019 1,176 B 32 B 1.00
New 12in 32.398 ns 0.0756 ns 0.0707 ns 0.88 - 693 B - 0.00
Old 12IN 43.497 ns 0.1695 ns 0.1585 ns 1.00 0.0038 1,176 B 64 B 1.00
New 12IN 31.147 ns 0.0807 ns 0.0755 ns 0.72 - 664 B - 0.00
Old 12pt 40.756 ns 0.0865 ns 0.0722 ns 1.00 0.0019 1,176 B 32 B 1.00
New 12pt 33.522 ns 0.0525 ns 0.0410 ns 0.82 - 679 B - 0.00
Old 12PT 46.214 ns 0.1658 ns 0.1551 ns 1.00 0.0038 1,176 B 64 B 1.00
New 12PT 34.190 ns 0.0717 ns 0.0636 ns 0.74 - 676 B - 0.00
Old 12px 35.508 ns 0.1054 ns 0.0985 ns 1.00 0.0019 1,176 B 32 B 1.00
New 12px 30.360 ns 0.0408 ns 0.0341 ns 0.85 - 630 B - 0.00
Old 12PX 40.378 ns 0.1564 ns 0.1463 ns 1.00 0.0038 1,176 B 64 B 1.00
New 12PX 29.259 ns 0.0727 ns 0.0644 ns 0.72 - 630 B - 0.00
Old auto 5.010 ns 0.0224 ns 0.0210 ns 1.00 - 656 B - NA
New auto 2.149 ns 0.0287 ns 0.0268 ns 0.43 - 509 B - NA

Customer Impact

Better perf and lower memory usage.

Regression

No.

Testing

Local testing.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner January 2, 2024 21:39
@ghost ghost assigned ThomasGoulet73 Jan 2, 2024
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jan 2, 2024
@ghost ghost requested review from dipeshmsft and singhashish-wpf January 2, 2024 21:39
@ghost ghost added the Community Contribution A label for all community Contributions label Jan 2, 2024
@pchaurasia14
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@lindexi lindexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

…rter-span

# Conflicts:
#	src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs
@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner August 23, 2024 03:34
@ThomasGoulet73
Copy link
Contributor Author

I updated my branch to main to fix a conflict and pushed a commit with the PR feedback.

harshit7962
harshit7962 previously approved these changes Aug 26, 2024
Copy link
Member

@harshit7962 harshit7962 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the changes looks good. Checked performance gain on multiple applications. There is about 4% gain on performance at xaml reading and it reflects out to be around 2% of gain at LoadComponent level when averaged out over multiple runs.

@h3xds1nz
Copy link
Member

Sounds amazing, I can't wait to push a PR benefiting from those changes! 😄

@harshit7962
Copy link
Member

harshit7962 commented Sep 13, 2024

@ThomasGoulet73 we have encountered a use case where the following changes are causing a regression. Please find the minimal repro here.

A bit of context, and to summarize the failure, the Height specified to Figure tag here does not take Content as a unit with these changes.

Can you please look if we can mitigate this failure. I believe we might need changes in XamlFigureLengthSerializer here and might have to possibly check for similar use case in XamlGridLengthSerializer.

@ThomasGoulet73
Copy link
Contributor Author

Hi @harshit7962, I think I found the problem. Here it should've been StringComparison.OrdinalIgnoreCase instead of StringComparison.Ordinal: https://github.com/dotnet/wpf/pull/8622/files#diff-e8d1ce9b0355662f53afd3f319bfcb23d2d2c8b1baa37572c7daacfed58bbf83R213

I looked at my other changes and they all use StringComparison.OrdinalIgnoreCase correctly, I'm not sure how I missed this one.

I'll test to make sure it fixes your repro later today.

@ThomasGoulet73
Copy link
Contributor Author

@harshit7962: I was able to reproduce the issue using your minimal repro and I have confirmed that the suspected fix in my previous comment did fix the issue.

Thank you for the simple repro!

@harshit7962 harshit7962 merged commit aa3e0ca into dotnet:main Sep 18, 2024
8 checks passed
@harshit7962
Copy link
Member

@ThomasGoulet73 verified that the edge case is fixed with the change. Thank you for your contributions.

@ThomasGoulet73 ThomasGoulet73 deleted the lengthconverter-span branch September 19, 2024 00:32
@ThomasGoulet73
Copy link
Contributor Author

Thanks @harshit7962

@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2024
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 PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants