-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Improve EventSource trimming #56154
Comments
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsUsing Creating an In .NET6, there was an effort to address trimming challenges with enhancements to the trimmer and changes to the
It is not reasonable to expect developers to understand the intricacies of trimming when they write event sources. We should make trimming
|
Event source is an example of reflection-based serializer. Every reflection-based serializer faces very similar set of problems with trimming. I believe source generators are the only sustainable way to solve them. |
Using
EventSource
to log data to a listener is fairly advanced (this blurb fromEventSource
describes the high level details). Even though .NET runtime take a lot of effort to hide the implementation details from developers who want to write their ownEventSource
, it can be still quite challenging to do so. A practical challenge that a user can run into can be seen at #27635.Creating an
EventSource
and using it in a trimmed applications make this situation almost untenable currently. Issue #32863 discusses some of the challenges. The trimmer has to reason about theEventSource
in libraries as well since there are increasingly proliferating number ofEventSources
in our runtime libraries.In .NET6, there was an effort to address trimming challenges with enhancements to the trimmer and changes to the
EventSource
code. The details below captures the current status with regards the unique characteristics ofEventSource
in trim mode;EventSource
is tagged with the attribute,DynamicallyAccessedMembersAttribute
, at the class level. This was done primarily to address generating a manifest for a derivedEventSource
type.- This means that the trimmer will preserve members of the full type inheritance graph for EventSource. Specifically, this can lead to situation like, Custom EventSources in shared library seem to have unused code #54859, where the current expectation from runtime library developers that the trimmer will get rid of unused methods cannot be honored.
EventSource
has some event methods that are marked withRequiresUnreferencedCodeAttribute
with parameters that could take non-primitive types. This was primarily to address the inability for the trimmer to handle complex serialization (there is a type recursion involving code here)- Any library
EventSource
that uses these methods need to be managed usually by addingUnconditionalSuppressMessageAttribute
attribute after checking that the specificEventSource
does not pass any non-primitive types to the parent method (or take steps to preserve the complex type).-
EventSources
that do not use the complex parent methods to send event data should not get any warnings-
EventSources
that do use the complex parent need to see the warning with actionable detailsEventSource
and its derived types continue to be treated in a special way in the trimmer in library mode trimming. In .NET 6.0, we moved the special handling logic to be only applicable in library mode via a flag (namedDisableEventSourceSpecialHandling
that is set to false in library mode). Specifically, preserve all static fields in nested types named"Keywords", "Tasks", "Opcodes"
inEventSource
derived types. Also preserve public instance methods that has the EventDataAttribute attribute.It is not reasonable to expect developers to understand the intricacies of trimming when they write event sources. We should make trimming
EventSource
seamless. Some options we should consider includeEventSource
code such that contract definition and implementation details are separate.EventSources
EventSource
tests to run in trim modeThe text was updated successfully, but these errors were encountered: