Skip to content

Optimize EventSource.GetGuid (NetEventSource) #120352

@EgorBo

Description

@EgorBo

When I was looking at #120288 rerpo which is just a simple console app with some Socket server & listener, I noticed a huge chunk of time is spent in NetEventSource::.cctor (Linux-x64 and I run the app without dotnet-trace or any env.vars). In that cctor most of the time is spent inside EventSource.GetGuid that is obtaining custom attributes (presumably over this type)

Image

Here is the GetGuid impl:

public static Guid GetGuid(Type eventSourceType)
{
ArgumentNullException.ThrowIfNull(eventSourceType);
EventSourceAttribute? attrib = (EventSourceAttribute?)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute));
string name = eventSourceType.Name;
if (attrib != null)
{
if (attrib.Guid != null)
{
if (Guid.TryParse(attrib.Guid, out Guid g))
return g;
}

Is this something we can avoid "GetCustomAttributes" for and replace with some static map for BCL types?

PS: this is not the root cause of #120288

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions