From dd1fe69042a0452f3302614cbf805be2011bf9b7 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sun, 3 Jun 2018 23:02:06 +0100 Subject: [PATCH 1/4] Perform JumpList creation in background thread to improve performance when pwsh owns the window (i.e. when the Jumplist has to be created) --- src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 02a8c1453e5..8b3b8adbaef 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -26,6 +26,7 @@ using Dbg = System.Management.Automation.Diagnostics; using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle; using System.Management.Automation.Tracing; +using System.Threading.Tasks; #if LEGACYTELEMETRY using Microsoft.PowerShell.Telemetry.Internal; #endif @@ -121,7 +122,7 @@ internal static int Start( #endif #if !UNIX - Microsoft.PowerShell.TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator); + Task.Run(() => TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator)); #endif // put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version From b2e0693f6e3f823ec365de39a054e703923fd3b6 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 4 Jun 2018 19:03:48 +0100 Subject: [PATCH 2/4] Move JumpList creation to a later stage to allow for more code that might make it exit earlier as suggested in PR review by @iSazonov --- .../host/msh/ConsoleHost.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 8b3b8adbaef..502a827e44a 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -121,10 +121,6 @@ internal static int Start( } #endif -#if !UNIX - Task.Run(() => TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator)); -#endif - // put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version string path = Environment.GetEnvironmentVariable("PATH"); if (path != null) @@ -215,6 +211,10 @@ internal static int Start( return ExitCodeBadCommandLineParameter; } +#if !UNIX + Task.Run(() => TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator)); +#endif + // First check for and handle PowerShell running in a server mode. if (s_cpp.ServerMode) { From d6369e4991acb0af0badffb9fd310b8754f44245 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 5 Jun 2018 07:52:03 +0100 Subject: [PATCH 3/4] add comments with details as requested in PR --- .../WindowsTaskbarJumpList/TaskbarJumpList.cs | 3 ++- .../host/msh/ConsoleHost.cs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs index 95096d91d92..69e4e264fa9 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs @@ -12,7 +12,8 @@ internal static class TaskbarJumpList { internal static void CreateElevatedEntry(string title) { - // check startupInfo to know if the current shell owns a window before proceeding + // Check startupInfo first to know if the current shell is interactive and owns a window before proceeding + // This check is fast (less than 1ms) and allows for quick-exit GetStartupInfo(out StartUpInfo startupInfo); var STARTF_USESHOWWINDOW = 0x00000001; var SW_HIDE = 0; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 502a827e44a..934971791bb 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -212,6 +212,12 @@ internal static int Start( } #if !UNIX + // Creating a JumpList entry takes around 55ms when the PowerShell process is interactive and + // owns the current window (otherwise it does a fast exit anyway). Since there is not 'GET' API, + // we always have to execute this call because we do not know if it has been created yet. + // The JumpList does persist as long as the filepath of the executable does not change but there + // could be disruptions to it like e.g. the bi-annual Windows update, we decided to + // not over-optimize this and always create the JumpList as a non-blocking background task instead. Task.Run(() => TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator)); #endif From 2c8becf0a30a8ac8ba089658198d4ea52479da51 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 5 Jun 2018 07:58:57 +0100 Subject: [PATCH 4/4] fix typo --- src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 934971791bb..c279d0cce15 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -213,7 +213,7 @@ internal static int Start( #if !UNIX // Creating a JumpList entry takes around 55ms when the PowerShell process is interactive and - // owns the current window (otherwise it does a fast exit anyway). Since there is not 'GET' API, + // owns the current window (otherwise it does a fast exit anyway). Since there is no 'GET' like API, // we always have to execute this call because we do not know if it has been created yet. // The JumpList does persist as long as the filepath of the executable does not change but there // could be disruptions to it like e.g. the bi-annual Windows update, we decided to