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

Stop allocating new delegates in WriterDelegate.Dispose #4771

Merged
merged 1 commit into from
Jul 23, 2021

Conversation

stephentoub
Copy link
Member

Description

Every call to Dispose is allocating one or two delegates. They're not unique to this instance; we can let the compiler cache them for us.

Customer Impact

Less allocation, less GC impact.

Regression

No

Testing

Just CI

Risk

Minimal. It's just changing one form of delegate creation to another.

Every call to Dispose is allocating one or two delegates.  They're not unique to this instance; we can let the compiler cache them for us.
@stephentoub stephentoub requested a review from a team as a code owner June 29, 2021 14:32
_addLineInfoDelegate = (_addLineInfoDelegate != null)
? new XamlLineInfoAddDelegate(ThrowBecauseWriterIsClosed2)
: null;
_addDelegate = delegate { throw new XamlException(SR.Get(SRID.WriterIsClosed)); };
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even need to set _addDelegate and _addLineInfoDelegate ? ThrowIsDisposed should already be called before the use of _addDelegate or _addLineInfoDelegate.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know. I'm just trying to maintain behavior just in case. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this PR is valid because it's faster than the existing code, which was already executed even if the new delegate is not invoked. A follow-up PR could be open to remove this "dead code" with more thorough testing to make sure that the delegates are never executed after dispose. I only said this over a quick glance over the code but they might be invoked.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think this PR is valid

It is 😄

@ryalanms ryalanms merged commit 9d95140 into dotnet:main Jul 23, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants