Skip to content

Slow AssemblyLoadContext.StartAssemblyLoad() at startup #45466

@iSazonov

Description

@iSazonov

Description

Related #44598
I measured PowerShell startup scenario with pwsh -c exit (really start-stop scenario).
One delay in the scenario is in AssemblyLoadContext.StartAssemblyLoad() called from hostpolicy - 59 ms (10%).

image

The StartAssemblyLoad() initializes tracing

private static void StartAssemblyLoad(ref Guid activityId, ref Guid relatedActivityId)
{
// Make sure ActivityTracker is enabled
ActivityTracker.Instance.Enable();
// Don't use trace to TPL event source in ActivityTracker - that event source is a singleton and its instantiation may have triggered the load.
ActivityTracker.Instance.OnStart(NativeRuntimeEventSource.Log.Name, AssemblyLoadName, 0, ref activityId, ref relatedActivityId, EventActivityOptions.Recursive, useTplSource: false);
}

Especially the slow System.Threading.Tasks.TplEventSource..cctor () - 49 ms (8.5%).
(And System.Diagnostics.Tracing.NativeRuntimeEventSource..cctor() too)

image

We can't seem to improve this in PowerShell and I hope it will be improved in .Net in some way. Perhaps it is possible to postpone the initialization or make it async.

Configuration

Used PowerShell 7.2 Preview.1 based on .Net 5.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tracing-coreclrenhancementProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions