On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed#638
On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed#638
Conversation
4de0624 to
3a27e74
Compare
…, do not set the console mode at all.PS Core, since the release of 6.0.0 has handled setting/resetting theconsole mode, so no need for posh-git to do this.This speeds up module import by ~.5 to .7 seconds on PSCore and by~150-200 msecs on Windows PowerShell.Fix #637
Keep this PR simple in scope - just the deferred Add-Type. After a chat w/lzybkr we may want to convert some of this to a binary to help import/prompt processing time.
|
Here's some profiling data. Current perf (without this PR): Now with just deferring the Add-Type until first use - which happens to be in the first call to Write-VcsStatus which happens the first time the prompt function is called: Now with not using Set-ConsoleMode on PS Core on Windows in a standard One thing I've noted is there is a significant stddev in the GitTabExpansion processing time. I've seen it range from 136 up to 499 ms. That might be good place to look next for module import perf improvements. |
I've seen that not using set-consolemode within VSCode/s PS integrated console causes problems after executing git log --graph --decorate.
0a48392 to
78ad465
Compare
| # On Windows, *if* we are running in PowerShell Core *and* the host is the "ConsoleHost", | ||
| # rely on PS Core to manage the console mode. This speeds up module import on standard | ||
| # PowerShell Core on Windows. | ||
| if (($IsWindows -eq $false) -or (($PSVersionTable.PSVersion.Major -ge 6) -and ($host.Name -eq 'ConsoleHost'))) { |
There was a problem hiding this comment.
This seems like a future extensibility point for other hosts that don't need Set-ConsoleMode, but this is good for now.
|
when will this be available in the beta? |
|
I still have a few lingering PRs to catch up with, but I'll try to ship a new beta in the next week or so. |
So, uh. Beta 3 shipped yesterday. 🙄 |
| { | ||
| $outputMode = [NativeConsoleMethods]::GetConsoleMode($false) | ||
| $null = [NativeConsoleMethods]::SetConsoleMode($false, $outputMode -bor [ConsoleModeOutputFlags]::ENABLE_VIRTUAL_TERMINAL_PROCESSING) | ||
| begin { |
There was a problem hiding this comment.
@rkeithhill What's the advantage of splitting this into begin/end?
There was a problem hiding this comment.
In this particular case, there is no advantage. Then again, there is no harm either. But I can simplify this if you'd like.
There was a problem hiding this comment.
No change necessary unless you find the alternative easier to read. Just curious if I was missing something.
On PS Core, do not set the console mode at all.
PS Core, since the release of 6.0.0 has handled setting/resetting the
console mode, so no need for posh-git to do this. See:
PowerShell/PowerShell#2991
This speeds up module import by ~.5 to .7 seconds on PSCore and by
~150-200 msecs on Windows PowerShell.
Fix #637 and maybe #635