Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add the DebuggableAttribute to System.Runtime.CompilerServices.Unsafe. - #40772

Merged
brianrob merged 1 commit into
dotnet:masterfrom
brianrob:debuggableattribute
Sep 3, 2019
Merged

brianrob merged 1 commit into
dotnet:masterfrom
brianrob:debuggableattribute

Conversation

@brianrob

@brianrob brianrob commented Sep 3, 2019

Copy link
Copy Markdown
Member

System.Runtime.CompilerServices.Unsafe.dll is produced from IL rather than C#, and so it does not by default have a DebuggableAttribute. As such, it is possible to end up in a place where JIT optimizations that are expected to be applied, such as inlining, are not due to the fact that the JIT uses the DebuggableAttribute as part of the calculation at inlining time. I believe that none of the methods in this assembly are currently affected, as they are all marked as aggressivelyinline, but going forward, any method that is not marked in such a way would likely not be inlined.

This change adds the appropriate DebuggableAttribute to Debug and Release versions of System.Runtime.CompilerServices.Unsafe.dll. This is the only assembly in the shared framework that does not have a DebuggableAttribute already. A search of CoreFx turned this assembly up as the only one that is IL-based.

NOTE: This PR is the result of a WPF performance investigation that identified the lack of a DebuggableAttribute as the reason that the JIT didn't inline things that it previously had. Ultimately, we found that the -DEBUG flag wasn't being passed to ilasm. Fixing this addressed the regression, and thus the desire to identify any other assemblies that might fall into this trap.

<!-- Make sure that the DebuggableAttribute is set properly. -->
<PropertyGroup>
<DebugOptimization>IMPL</DebugOptimization>
<DebugOptimization Condition="'$(ConfigurationGroup)' == 'Release'">OPT</DebugOptimization>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a downside to just always using OPT for this project?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not 100% sure. I was attempting to match what we see for debug and release builds on other binaries in an attempt to not make this one special.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok

@stephentoub stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Assuming you've validated the resulting binaries look the way we desire, LGTM.

@brianrob

brianrob commented Sep 3, 2019

Copy link
Copy Markdown
Member Author

Excellent. Thanks. Yes, I have validated that the attribute is set correctly.

@brianrob
brianrob merged commit f9c848d into dotnet:master Sep 3, 2019
@brianrob
brianrob deleted the debuggableattribute branch September 3, 2019 20:07
@karelz karelz added this to the 5.0 milestone Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants