Remove some overhead from Process.Start (#44691)
authorStephen Toub <stoub@microsoft.com>
Tue, 17 Nov 2020 22:48:19 +0000 (17:48 -0500)
committerGitHub <noreply@github.com>
Tue, 17 Nov 2020 22:48:19 +0000 (17:48 -0500)
commitef2a1878793e7e3fc3060396d3d2655ac53b1316
treed22af45c4a6bc4cd996ec7a3d2a022d1307ed6ce
parent38743da37ad435fafa599ec9e375ee5368578734
Remove some overhead from Process.Start (#44691)

- Avoid StringBuilder marshaling
- Let CreateProcess{WithLogonW} determine the current working directory
- Avoid creating SafeHandles for GetCurrentProcess()
- Avoid forcing ProcessStartInfo.ArgumentList into existence just to check if it contains anything
- Prefer using ProcessStartInfo.Arguments in Start(string, IEnumerable<string>) if there's only one string in the enumerable
- Use ValueStringBuilder instead of StringBuilder to build up arguments, so as to use stack space / pooled char[]s and avoid actually needing to produce strings.
- Avoid unnecessary SafeHandle for PROCESS_INFORMATION.hThread
27 files changed:
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.OpenProcessToken.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateProcess.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafeAccessTokenHandle.cs [moved from src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle.cs with 90% similarity]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafeFileHandle.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafePipeHandle.cs [moved from src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_IntPtr.cs with 71% similarity]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafeProcessHandle.cs [deleted file]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafeWaitHandle.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcess.cs [moved from src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcess_IntPtr.cs with 100% similarity]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcess_SafeProcessHandle.cs [deleted file]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ProcessWaitHandle.cs
src/libraries/Common/tests/TestUtilities/System/AdminHelpers.cs
src/libraries/Common/tests/TestUtilities/TestUtilities.csproj
src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj
src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj
src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/PasteArguments.Unix.cs
src/libraries/System.Private.CoreLib/src/System/PasteArguments.Windows.cs
src/libraries/System.Private.CoreLib/src/System/PasteArguments.cs
src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj
src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj