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

Skip the ConsoleMode hack for new Windows versions #637

Closed
lhecker opened this issue Oct 31, 2018 · 3 comments
Closed

Skip the ConsoleMode hack for new Windows versions #637

lhecker opened this issue Oct 31, 2018 · 3 comments

Comments

@lhecker
Copy link

lhecker commented Oct 31, 2018

System Details

  • posh-git version/path: 1.0.0 beta2 ~\Documents\PowerShell\Modules\posh-git\1.0.0
  • PowerShell version: 6.1.0
  • git version 2.19.1.windows.1
  • OS: Microsoft Windows NT 10.0.17763.0

Issue Description

Thank you for this wonderful project!
Sadly though I'm a bit dissatisfied with the startup speed (1000-1300ms) and tried improving the situation.

While doing so I realized that if I remove these 2 lines:

everything still works as it used to - including ANSI escape codes!

But now startup time is reduced by 30-50% down to around 500-600ms!

Could this be because in the newest Windows versions HKCU:\Console\VirtualTerminalLevel is 1 by default now? Because I personally don't have that registry key set at all.

If we could add some kind of check for this we could skip running the expensive ConsoleMode hack, no-op the Set-ConsoleMode function and thus significantly improve startup time.

I'm fairly inexperienced in proper PowerShell scripting and thus I don't have a proper idea how we can do this in a backwards-compatible way, but I'm happy to help wherever I can. 🙂

@rkeithhill
Copy link
Collaborator

rkeithhill commented Oct 31, 2018

That's a good idea. I'm looking into it. I wonder what happens if you run your console in legacy mode though.

@lhecker
Copy link
Author

lhecker commented Oct 31, 2018

After pondering about this for a while I actually don't think that this is achievable by removing the ConsoleMode stuff.

But I found another way: Add-Type provides the -OutputAssembly and -Path options using which we can cache the assembled C# code in a .dll!
With this idea in mind I hacked together the following: master...lhecker:master
Let me know what you think about it! 🙂

I took the liberty to remove unused C# code and was thus able to remove more code than I added.
GitPrompt.ps1 btw was encoded as UTF-8 with BOM - I removed the BOM. 🙂

@rkeithhill
Copy link
Collaborator

That might be part of the solution but not the whole solution. Another option for creating a DLL would be to just do that as part of the module build process but I don't think we need to go there yet. I've got a PR planned for later tonight that should address this if one of my assumptions is correct. :-)

rkeithhill added a commit that referenced this issue 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.

This speeds up module import by ~.5 to .7 seconds on PSCore and by
~150-200 msecs on Windows PowerShell.

Fix #637
rkeithhill added a commit that referenced this issue Nov 2, 2018
…, 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
rkeithhill added a commit that referenced this issue Nov 3, 2018
…, 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
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

No branches or pull requests

2 participants