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

Set-PSReadLineOption is slow when called from profile #4022

Open
3 tasks done
RoadToDream opened this issue May 25, 2024 · 14 comments
Open
3 tasks done

Set-PSReadLineOption is slow when called from profile #4022

RoadToDream opened this issue May 25, 2024 · 14 comments
Labels
Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.

Comments

@RoadToDream
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

measure-command { Set-PSReadLineOption -HistoryNoDuplicates -EditMode Windows }

image
image

Environment data

PS Version: 7.4.2
PS HostName: ConsoleHost
PSReadLine Version: 2.3.5
PSReadLine EditMode: Windows
OS: 10.0.22621.1 (WinBuild.160101.0800)
BufferWidth: 181
BufferHeight: 23

Steps to reproduce

This has been reported in #476, but closed without much context been provided.
Set-PSReadLineOption calling from profile will take much longer than calling from a running pwsh. Adding a single line of Set-PSReadLineOption in profile delays start up time over 100 ms. I wonder how is the 11 ms load time is achieved mentioned in that issue and what can I do to ease the issue.

Expected behavior

Same execution time when running from profile.

Actual behavior

Much longer execution time in profile.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label May 25, 2024
@daxian-dbw
Copy link
Member

Do you mean Set-PSReadlineOption is slow in general or only the Set-PSReadLineOption -HistoryNoDuplicates -EditMode Windows is slow for you?

Adding a single line of Set-PSReadLineOption in profile delays start up time over 100 ms.

I cannot reproduce the issue locally. I have 3 calls to Set-PSReadlineOption in my profile and cannot observe a delay as reported

@RoadToDream
Copy link
Author

Hi, for me it's the general Set-PSReadlineOption. Even a single Set-PSReadlineOption will introduce over 100 ms delay.
If it's not reproducible I assume there is something wrong from my end, may I ask if there is any log I may collect that can help diagnose this issue?
Thanks

@daxian-dbw
Copy link
Member

Even Set-PSReadlineOption -BellStyle None takes over 100ms for you in profile?

may I ask if there is any log I may collect that can help diagnose this issue?

If you really want to dig into it, I guess you will have to collect traces using prefview, which is not easy for a starter.

You will need to build PSReadLine locally with the Release configuration .\build.ps1 -Framework net462 -Configuration Release and use the produced module to collect the trace.
After the build, you can find the produced PSReadLine module under .\bin\Release\PSReadLine, and the .pdb file for Microsoft.PowerShell.PSReadLine2.dll can be found under .\PSReadLine\bin\Release\net462.

@RoadToDream
Copy link
Author

RoadToDream commented May 31, 2024

That's true.
image

Thanks for the instruction. I am indeed a starter for C# but will give it a try

@daxian-dbw
Copy link
Member

daxian-dbw commented May 31, 2024

@gwojan
Copy link

gwojan commented May 31, 2024

Hi, for me it's the general Set-PSReadlineOption. Even a single Set-PSReadlineOption will introduce over 100 ms delay. If it's not reproducible I assume there is something wrong from my end, may I ask if there is any log I may collect that can help diagnose this issue? Thanks

Just out of curiosity do you have some other software running that might be causing issues, ie: Defender, FireEye, etc. My work laptop frequently has performance issues running my wacky PowerShell profile because of those two specific applications scanning all the things. 😭

My latest issue was I have a function Get-Fortune which calls into WSL using fortune, cowsay, and lolcat to display my fortune in each new PowerShell session. About two weeks ago my profile load times went from maybe one second to 35 seconds! It turns out I have a really old script that maps a persistent drive to a now non-existent resource. Waiting for WSL was causing my extreme slowdowns so once I removed the mapped drive performance was back to normal.

@RoadToDream
Copy link
Author

Thanks for the suggestion. I can take a look, but honestly, I don't think that's the reason. I have disabled Defender.

@RoadToDream
Copy link
Author

RoadToDream commented Jun 1, 2024

Let me put some profiling result here.
I am using prefview to profile, each configuration is executed 10 times for averaging.

image
Fig. 1 With PSReadLine option: Set-PSReadLineOption -EditMode Emacs

image
Fig. 2 Without PSReadLine option

@RoadToDream
Copy link
Author

Flame graphs
image
Fig. 1 With PSReadLine option: Set-PSReadLineOption -EditMode Emacs
image
Fig. 2 Without PSReadLine option

@RoadToDream
Copy link
Author

RoadToDream commented Jun 3, 2024

I am not sure if this information is sufficient to help diagnose the issue, but if not, please let me know and I can provide more details. I am much more familiar with VTune, so if that would help, I can provide information from that as well.

Based on my findings so far, the issue seems more likely to be related to PowerShell rather than PSReadLine.

@StevenBucher98
Copy link
Collaborator

Just out of curiosity does the startup time only increase with that particular command or does it increase with anything in your profile?

@RoadToDream
Copy link
Author

RoadToDream commented Jun 10, 2024

Hi @StevenBucher98, it increases with any line with Set-PSReadlineOption.
However, adding one config line of Set-PSReadlineOption takes about same time as adding four or five.

@konosubakonoakua
Copy link

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.
Projects
None yet
Development

No branches or pull requests

5 participants