Up to 1 second delay in Windows 11 when launching console apps outside of terminal when Windows Terminal is set as default console host #15829

Closed
opened 2026-01-31 04:49:39 +00:00 by claunia · 1 comment
Owner

Originally created by @pervognsen on GitHub (Nov 9, 2021).

Windows Terminal version (or Windows build number)

10.0.22000.0, 1.12.2931.0

Other Software

No response

Steps to reproduce

I have a win32 console subsystem application, which I normally run directly from a Powershell instance under Windows Terminal. It runs in about 40ms when I measure its running time with Measure-Command. I happened to be profiling this app with a third-party profiler (Superluminal) which made me notice it was spending about 1 second in the Ldr code that's responsible for loading the executable image (and its DLL dependencies).

Essentially all of that 1 second is spent blocked in the ConsoleInitialize call stack. I attached a screenshot so you can see for yourself.

image

I'm on Windows 11 and have Windows Terminal Preview (with the reported version number) set as my default terminal application. If I set the default terminal application back to Windows Console Host, the same Ldr code path only consumes 50ms instead of 1s.

Edit: I did an ETW trace which confirms that the console app is waiting on OpenConsole.exe -> WindowsTerminal.exe.

Edit: I did a bunch more traces and most of them take closer to 300 ms than 1 s. The lower end numbers are less egregious and I probably wouldn't have filed this issue if my initial measurements were in that lower range. In any case, I'll leave this issue here in case you think something here merits investigation.

Expected Behavior

Console applications should start up instantaneously even when launched from outside of terminal.

Actual Behavior

ConsoleInitialize code path takes ~1s to complete.

Originally created by @pervognsen on GitHub (Nov 9, 2021). ### Windows Terminal version (or Windows build number) 10.0.22000.0, 1.12.2931.0 ### Other Software _No response_ ### Steps to reproduce I have a win32 console subsystem application, which I normally run directly from a Powershell instance under Windows Terminal. It runs in about 40ms when I measure its running time with Measure-Command. I happened to be profiling this app with a third-party profiler (Superluminal) which made me notice it was spending about 1 second in the Ldr code that's responsible for loading the executable image (and its DLL dependencies). Essentially all of that 1 second is spent blocked in the ConsoleInitialize call stack. I attached a screenshot so you can see for yourself. ![image](https://user-images.githubusercontent.com/123173/141012490-0962d9b8-cde7-4e43-a8e2-3eeaeb6e2f00.png) I'm on Windows 11 and have Windows Terminal Preview (with the reported version number) set as my default terminal application. If I set the default terminal application back to Windows Console Host, the same Ldr code path only consumes 50ms instead of 1s. Edit: I did an ETW trace which confirms that the console app is waiting on OpenConsole.exe -> WindowsTerminal.exe. Edit: I did a bunch more traces and most of them take closer to 300 ms than 1 s. The lower end numbers are less egregious and I probably wouldn't have filed this issue if my initial measurements were in that lower range. In any case, I'll leave this issue here in case you think something here merits investigation. ### Expected Behavior Console applications should start up instantaneously even when launched from outside of terminal. ### Actual Behavior ConsoleInitialize code path takes ~1s to complete.
Author
Owner

@miniksa commented on GitHub (Nov 10, 2021):

Hey there @pervognsen. Great investigation! You've discovered pretty much exactly what I would have done if I were to trace and profile the route.

You are correct that it is likely waiting on that handoff from OpenConsole.exe to WindowsTerminal.exe. The entire thing is sort of a synchronous block until everyone is ready to start filling their buffers with incoming data.

The 1 second is not great. I'm with you there. 300ms is more reasonable. Either way we look at it, though, since Windows Terminal has "more" going on than the original console host did... it is going to take more time and effort to stand up.

I'm betting that the subsequent launches weren't as bad due to the DLLs needed being hot somewhere in some cache.

Long term, I think what we'll need to work on here is having some portions of the Terminal reside in pre-launch cache and/or work on our idea to have a background service resident and waiting to catch things like the quake mode key (#9996) and perhaps juice up the startup of inbound connections by having things partially already ready to go. We also likely need to continue our work with the XAML team and the Performance teams to work on what we can do to speed up launch. Additionally, we have our Engineering Improvement Month coming up starting next week... and one of my tasks is to look at PGO... including for launch speed. #11688

Hopefully between those things, we'll improve this story more and more over time.

In the meantime... if you need that super fast performance, you'll have to turn the Terminal off as your default application. Though if you do capture any particularly egregious ETL traces, I'd be happy to have them so I can try to identify areas where we can speed up the launch or improve the PGO training.

Thank you for your report.

@miniksa commented on GitHub (Nov 10, 2021): Hey there @pervognsen. Great investigation! You've discovered pretty much exactly what I would have done if I were to trace and profile the route. You are correct that it is likely waiting on that handoff from OpenConsole.exe to WindowsTerminal.exe. The entire thing is sort of a synchronous block until everyone is ready to start filling their buffers with incoming data. The 1 second is not great. I'm with you there. 300ms is more reasonable. Either way we look at it, though, since Windows Terminal has "more" going on than the original console host did... it is going to take more time and effort to stand up. I'm betting that the subsequent launches weren't as bad due to the DLLs needed being hot somewhere in some cache. Long term, I think what we'll need to work on here is having some portions of the Terminal reside in pre-launch cache and/or work on our idea to have a background service resident and waiting to catch things like the quake mode key (#9996) and perhaps juice up the startup of inbound connections by having things partially already ready to go. We also likely need to continue our work with the XAML team and the Performance teams to work on what we can do to speed up launch. Additionally, we have our Engineering Improvement Month coming up starting next week... and one of my tasks is to look at PGO... including for launch speed. #11688 Hopefully between those things, we'll improve this story more and more over time. In the meantime... if you need that super fast performance, you'll have to turn the Terminal off as your default application. Though if you do capture any particularly egregious ETL traces, I'd be happy to have them so I can try to identify areas where we can speed up the launch or improve the PGO training. Thank you for your report.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15829