mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Improve startup time by triggering initialization of additional types on background thread (#18195)
This commit is contained in:
@@ -44,22 +44,28 @@ namespace System.Management.Automation.Runspaces
|
||||
|
||||
// We shouldn't create too many tasks.
|
||||
#if !UNIX
|
||||
// Amsi initialize can be a little slow
|
||||
// Amsi initialize can be a little slow.
|
||||
Task.Run(() => AmsiUtils.WinScanContent(content: string.Empty, sourceMetadata: string.Empty, warmUp: true));
|
||||
#endif
|
||||
// Initialize the types 'Compiler', 'CachedReflectionInfo', and 'ExpressionCache'.
|
||||
// Their type initializers do a lot of reflection operations.
|
||||
// We will access 'Compiler' members when creating the first session state.
|
||||
Task.Run(() => _ = Compiler.DottedLocalsTupleType);
|
||||
|
||||
// One other task for other stuff that's faster, but still a little slow.
|
||||
Task.Run(() =>
|
||||
{
|
||||
// Loading the resources for System.Management.Automation can be expensive, so force that to
|
||||
// happen early on a background thread.
|
||||
// Loading the resources for System.Management.Automation can be expensive,
|
||||
// so force that to happen early on a background thread.
|
||||
_ = RunspaceInit.OutputEncodingDescription;
|
||||
|
||||
// This will init some tables and could load some assemblies.
|
||||
_ = TypeAccelerators.builtinTypeAccelerators;
|
||||
// We will access 'LanguagePrimitives' when binding built-in variables for the Runspace.
|
||||
LanguagePrimitives.GetEnumerator(null);
|
||||
|
||||
// This will init some tables and could load some assemblies.
|
||||
LanguagePrimitives.GetEnumerator(null);
|
||||
// We will access 'TypeAccelerators' when auto-loading the PSReadLine module, which happens last.
|
||||
_ = TypeAccelerators.builtinTypeAccelerators;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user