-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Background and motivation
Public EventSource constructors perform a lot of reflection to compute the name to register EventSource with, and compute SHA1 hash to compute the registration GUID. The proposed API enables generating the name and GUID via a source generator instead.
This source generator exists as internal for Corelib today. This proposal changes internal EventSource .ctors that take Guid and name to protected
API Proposal
class EventSource
{
protected EventSource(Guid eventSourceGuid, string eventSourceName);
protected EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[] traits = null);
}API Usage
The API is expected to be used by source generator. Example of generated source:
internal MyEventSource() : base(new Guid(0x0866b2b8,0x5cef,0x5db9,0x26,0x12,0x0c,0x0f,0xfd,0x81,0x4a,0x44), "System.MyEventSource") { }Alternative Designs
No response
Risks
No response
The non Guid .ctors cause a lot of reflection to look up the Guid and name from the applied attribute and for first use a lot of Jit compilation of the reflection methods:
Which if it is in the startup path directly impacts startup times.
For coreclr they can use the internal .ctors dotnet/coreclr#21714, dotnet/coreclr#16054, dotnet/coreclr#16060
However there are still many corefx, aspnet and other app model EventSources that get triggered on startup and cannot use these .ctor overloads (e.g. Microsoft-Diagnostics-DiagnosticSource, Microsoft-System-Net-Sockets, Microsoft-System-Net-NameResolution, Microsoft-AspNetCore-Hosting, Microsoft-Extensions-DependencyInjection) and directly impact startup time:
/cc @jkotas

