Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pervognsen opened this issue Nov 9, 2021 · 1 comment
Labels
Area-Performance Performance-related issue Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-Answered Related to questions that have been answered

Comments

@pervognsen
Copy link

pervognsen commented 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.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Nov 9, 2021
@pervognsen pervognsen changed the title 1 second delay in Windows 11 when launching console apps outside of terminal when Windows Terminal is set as default console host Up to 1 second delay in Windows 11 when launching console apps outside of terminal when Windows Terminal is set as default console host Nov 9, 2021
@miniksa
Copy link
Member

miniksa commented 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 miniksa closed this as completed Nov 10, 2021
@miniksa miniksa added Issue-Question For questions or discussion Resolution-Answered Related to questions that have been answered Area-Performance Performance-related issue Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Nov 10, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Performance Performance-related issue Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

2 participants