Speed up clink injection by not suspending threads#507
Speed up clink injection by not suspending threads#507jalfd wants to merge 2 commits intomridgers:masterfrom
Conversation
cmd.exe is a singlethreaded application. When it is waiting for another process (such as clink) to finish, it is blocked in WaitForSingleObject(). That means there's no need to suspend its threads before injecting. This is useful as enumerating all the threads on the machine frequently takes around a third of a second, and this cost is incurred even if cmd is started with /c, meaning it slows down script execution in non-interactive shells as well.
That's only true when clink is being injected into the same cmd.exe that spawned the clink inject command. The This change sounds like it may accidentally remove support for less common ways that clink can be injected. Perhaps there could be a flag so that it's not the default way, but can be forced if the user is willing to take the risk. |
That's true. I hadn't considered that use case (because I don't use it). Thanks for spotting that! |
Iterating over every thread on the system takes a lot of time, and is unnecessary as
cmd.exeis already blocked (waiting inWaitForSingleObject()) whenever clink is being injected. So just don't do it.Also add a few
static_cast's to silence warnings in VS2017 about narrowing conversions.