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

On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed #638

Merged
merged 3 commits into from
Nov 11, 2018

Conversation

rkeithhill
Copy link
Collaborator

@rkeithhill rkeithhill commented Nov 1, 2018

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

…, 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.
@rkeithhill rkeithhill changed the title On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed WIP: On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed Nov 3, 2018
@rkeithhill
Copy link
Collaborator Author

Here's some profiling data.

Current perf (without this PR):

WARNING: CheckRequirements.ps1 load time: 89
WARNING: ConsoleMode.ps1 load time: 930 <<< ~1 second here!!!
WARNING: Utils.ps1 load time: 136
WARNING: AnsiUtils.ps1 load time: 34
WARNING: WindowTitle.ps1 load time: 8
WARNING: PoshGitTypes.ps1 load time: 28
WARNING: GitUtils.ps1 load time: 37
WARNING: GitPrompt.ps1 load time: 90
WARNING: GitParamTabExpansion.ps1 load time: 35
WARNING: GitTabExpansion.ps1 load time: 140
WARNING: TortoiseGit.ps1 load time: 10
WARNING: Process through configuring prompt func: 27
WARNING: Process through end: 5
WARNING: Total pms1 import time: 1592
Loading personal and system profiles took 2672ms.
C:\Users\Keith
11-02 23:08:00 232ms 1> << note that prompt processing time is pretty short

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:

WARNING: CheckRequirements.ps1 load time: 90
WARNING: ConsoleMode.ps1 load time: 32  <<< Wow! this is much better
WARNING: Utils.ps1 load time: 154
WARNING: AnsiUtils.ps1 load time: 33
WARNING: WindowTitle.ps1 load time: 8
WARNING: PoshGitTypes.ps1 load time: 29
WARNING: GitUtils.ps1 load time: 38
WARNING: GitPrompt.ps1 load time: 102
WARNING: GitParamTabExpansion.ps1 load time: 33
WARNING: GitTabExpansion.ps1 load time: 150
WARNING: TortoiseGit.ps1 load time: 18
WARNING: Process through configuring prompt func: 30
WARNING: Process through end: 5
WARNING: Total pms1 import time: 745
Loading personal and system profiles took 1817ms.  <<< Profile load time looks better
C:\Users\Keith
11-02 23:11:08 1044ms 1>   <<< But we played a shell game and move the time here  232 > 1044 ms

Now with not using Set-ConsoleMode on PS Core on Windows in a standard ConsoleHost (here we come out pretty good all around):

WARNING: CheckRequirements.ps1 load time: 90
WARNING: ConsoleMode.ps1 load time: 25  <<< Good!
WARNING: Utils.ps1 load time: 147
WARNING: AnsiUtils.ps1 load time: 31
WARNING: WindowTitle.ps1 load time: 8
WARNING: PoshGitTypes.ps1 load time: 34
WARNING: GitUtils.ps1 load time: 41
WARNING: GitPrompt.ps1 load time: 104
WARNING: GitParamTabExpansion.ps1 load time: 30
WARNING: GitTabExpansion.ps1 load time: 136
WARNING: TortoiseGit.ps1 load time: 11
WARNING: Process through configuring prompt func: 30
WARNING: Process through end: 6
WARNING: Total pms1 import time: 714
Loading personal and system profiles took 1840ms.
C:\Users\Keith
11-02 23:14:13 221ms 1>  <<< Good!

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.
@rkeithhill rkeithhill changed the title WIP: On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed On Windows PowerShell, defer Add-Type until Set-ConsoleMode executed Nov 5, 2018
# 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'))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a future extensibility point for other hosts that don't need Set-ConsoleMode, but this is good for now.

@dahlbyk dahlbyk merged commit ce6381b into master Nov 11, 2018
@dahlbyk dahlbyk deleted the rkeithhill/defer-add-type branch November 11, 2018 20:03
@musm
Copy link

musm commented Nov 13, 2018

when will this be available in the beta?

@dahlbyk
Copy link
Owner

dahlbyk commented Nov 13, 2018

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.

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 11, 2019

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkeithhill What's the advantage of splitting this into begin/end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, there is no advantage. Then again, there is no harm either. But I can simplify this if you'd like.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change necessary unless you find the alternative easier to read. Just curious if I was missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants