Skip to content
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

Slow AssemblyLoadContext.StartAssemblyLoad() at startup #45466

Open
iSazonov opened this issue Dec 2, 2020 · 6 comments
Open

Slow AssemblyLoadContext.StartAssemblyLoad() at startup #45466

iSazonov opened this issue Dec 2, 2020 · 6 comments
Labels
area-Tracing-coreclr enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Milestone

Comments

@iSazonov
Copy link
Contributor

iSazonov commented Dec 2, 2020

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.

@iSazonov iSazonov added the tenet-performance Performance related issue label Dec 2, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner labels Dec 2, 2020
@ghost
Copy link

ghost commented Dec 2, 2020

Tagging subscribers to this area: @vitek-karas, @agocke, @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: iSazonov
Assignees: -
Labels:

area-AssemblyLoader-coreclr, tenet-performance, untriaged

Milestone: -

@jkotas
Copy link
Member

jkotas commented Dec 2, 2020

EventSource construction is relatively expensive reflection heavy operation today.

The ultimate way to fix this overhead is to replace the reflection with source generators: #43390

@iSazonov
Copy link
Contributor Author

iSazonov commented Dec 2, 2020

EventSource construction is relatively expensive reflection heavy operation today.

The ultimate way to fix this overhead is to replace the reflection with source generators: #43390

In the my trace for startup scenario it seems a reflection calls take <0.8% but System.Resources.ResourceManager.GetString() 1.2%.
I doubt that generators will help in this scenario.
If this initialization cannot be postponed, then most likely it is necessary to improve a little bit of all parts
/cc @adamsitnik

@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Dec 7, 2020
@tommcdon tommcdon added this to the 6.0.0 milestone Dec 7, 2020
@tommcdon
Copy link
Member

tommcdon commented Dec 7, 2020

@josalem

@benaadams
Copy link
Member

In the my trace for startup scenario it seems a reflection calls take <0.8% but System.Resources.ResourceManager.GetString() 1.2%.

Looking at the stacktrace It's the manifest generation; System.Resources.ResourceManager.GetString is being called as the TplEventSource has a translatable manifest.

Source generators should still help here.

@tommcdon
Copy link
Member

Related to #45518

@noahfalk noahfalk added the enhancement Product code improvement that does NOT require public API changes/additions label Jan 12, 2021
@tommcdon tommcdon modified the milestones: 6.0.0, 7.0.0 Jun 16, 2021
@tommcdon tommcdon modified the milestones: 7.0.0, Future May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tracing-coreclr enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

6 participants