Skip to content

Update ref performance article(s) for C# 11#32997

Merged
BillWagner merged 20 commits intodotnet:mainfrom
BillWagner:refer-madness
Feb 7, 2023
Merged

Update ref performance article(s) for C# 11#32997
BillWagner merged 20 commits intodotnet:mainfrom
BillWagner:refer-madness

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Dec 13, 2022

This article was originally created in the C# 7 wave. Several improvements in this area have happened since then. We've added many features around the general concept of using ref variables and `ref assignment. Rework this article into an overview and a tutorial that cover the feature.

The overview describes the the problem space and the techniques to improve performance using struct types and references instead of values.

The tutorial starts with a program that creates numerous unnecessary allocations. Each step demonstrates one of the techniques to remove allocations, preserve the original semantics, and clarify expectations on data modification.

Fixes #32668

Several other issues related to this issue are also fixed in this PR

Fixes #27175 - Add note about readonly modifier on auto-implemented properties.
Fixes #27199 - Include init-only properties as well for readonly.
Fixes #27201 - add note about init only properties marked as readonly.
Fixes #27202 - remove duplicate notes about ref assignment and readonly ref assignment.
Fixes #27203 - reword sentence.
Fixes #27205 - reword description, remove duplicate explanation
Fixes #27208 - clarify internal reference.
Fixes #32594 - lower the strength of the specific recommendation.


@dotnet-bot dotnet-bot added this to the December 2022 milestone Dec 13, 2022
@ghost ghost added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Dec 13, 2022
@BillWagner BillWagner force-pushed the refer-madness branch 4 times, most recently from 716923e to a250604 Compare December 16, 2022 16:47
@BillWagner BillWagner modified the milestones: December 2022, January 2023 Jan 5, 2023
@BillWagner BillWagner force-pushed the refer-madness branch 2 times, most recently from caee42b to 89c0007 Compare January 11, 2023 14:34
@BillWagner BillWagner force-pushed the refer-madness branch 2 times, most recently from 4c5805d to c83a522 Compare January 19, 2023 16:35
- Add a new top level node for "Advanced topics". Under that node are the Roslyn SDK and the new performance node.
- Move existing topic.
- Add redirects
- Add new outline

fix current build warnings
Making these edits first will make it easier to chop this up and reorganize without losing the context in these issues.
Ignore the old-stuff.md file. That's a checkpoint so I don't lose any text until it's converted
BillWagner added a commit to BillWagner/samples that referenced this pull request Jan 23, 2023
This sample has the starter app and finished application for the tutorial added in dotnet/docs#32997

The tutorial shows the reader how to analyze when your application is allocating memory unnecessarily, and how you can use the profiler tools and the C# language `ref` safety features to improve performance.
@BillWagner BillWagner marked this pull request as ready for review January 27, 2023 14:51
Copy link

@CamSoper CamSoper left a comment

Choose a reason for hiding this comment

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

In the tutorial, my program had unexpected output. Lot's of values were 0 or NaN. Totally willing to believe I missed something in the text but I'm not seeing it.

image

On further review (thanks, WinMerge!) it looks like there were changes that I was supposed to make that weren't clear in Program.cs and Room.cs.

image

image

BillWagner and others added 2 commits February 1, 2023 11:03
Co-authored-by: Cam Soper <cam.soper@microsoft.com>
Add steps missing from the tutorial.
@BillWagner
Copy link
Member Author

Thanks @CamSoper

I've addressed all the feedback.

Copy link

@CamSoper CamSoper left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member Author

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Thanks a lot @cston This is really helpful.

I addressed all the feedback. One set of changes was to rewrite a paragraph. Can you give that change in the final commit another look?

Thanks again.

@BillWagner BillWagner modified the milestones: January 2023, February 2023 Feb 3, 2023
@BillWagner BillWagner enabled auto-merge (squash) February 7, 2023 16:30
@BillWagner BillWagner merged commit ad27411 into dotnet:main Feb 7, 2023
@BillWagner BillWagner deleted the refer-madness branch February 7, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dotnet-csharp/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Projects

None yet

4 participants