Enable pwsh ReadLine to use PSReadLine · Issue #7971 · PowerShell/PowerShell · GitHub
Skip to content

Enable pwsh ReadLine to use PSReadLine #7971

Closed

Description

@edyoung

In pwsh on linux, hold down a key, and observe the rate at which characters are added. Then run Read-Host and observe the rate at which characters are added - it is much slower. In both cases I'm just holding down the f key. This is even slower in Cloud Shell, but the issue is reproducible in a regular terminal on ubuntu. The characters are also buffered differently - if you hold down a key and then release it in the normal terminal, input stops quickly after you release it. In Read-Host, the characters are still being added to the input and displayed several seconds after you release the key.

Why does it matter? Several customers have complained. This also shows up when using Get-Credential.

Screen recording below

read-host

> $PSVersionTable
PSVersion 6.1.0
PSEdition Core
OS Linux 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018

Activity

  1. dend commented on Oct 8, 2018

    @dend

    This is affecting the customers' experience with the Cloud Shell on docs.microsoft.com, especially in cases where we work with them to provision Azure resources and they need to specify information such as VM names, passwords or resource group.

  2. jianyunt commented on Oct 8, 2018

    @jianyunt
    Contributor

    I think I discussed it with Bruce Payette (@BrucePay) before. We also observed the issue.

    These interactive cmdlets including read-host, get-credential are handled by pwsh, yes?
    I noticed that if you remove-module psreadline, regular stdout becomes lagging too. The behavior is much like read-host and get-cred. Does this mean the lagging could be caused by powershell engine? Of course pwsh depends PSReadline which should not be removed.

  3. SteveL-MSFT commented on Oct 9, 2018

    @SteveL-MSFT
    Member

    The issue here is that PowerShell Core ConsoleHost has a very simple synchronous readline implementation. When you use Read-Host, it calls back into the host's ReadLine() implementation which is not designed to be performant. PSReadLine on the other hand is what you use in the console when not using Read-Host. PSReadLine buffers the input asynchronously and renders them on a different thread.

  4. added
    WG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Oct 9, 2018
  5. vexx32 commented on Oct 9, 2018

    @vexx32
    Collaborator

    In the efforts of a (hopefully) simple fix, is it possible for PSReadLine to override the Read-Host with a function/cmdlet/alias that works in a similar fashion to how it handles standard input?

  6. iSazonov commented on Oct 9, 2018

    @iSazonov
    Collaborator

    I started some ConHost optimizations, but my PR for ConHost has been awaiting a review for several months. I could continue these optimizations, but reviews is required.

  7. lzybkr commented on Oct 22, 2018

    @lzybkr
    Contributor

    PSReadLine could be modified to support Read-Host, but it might be simpler and/or smarter to better understand why Console.ReadLine is so slow.

    To modify PSReadLine to support Read-Host, you'd need to:

    • Not use the PowerShell syntax coloring
    • Not share history, possibly not use history at all
    • Add support for reading a secure string
    • Disable completion

    I've briefly considered a readline implementation that implements parts of the LSP for reuse in other tools like csi and fsi, if that ever gets built, then I think Read-Host would be a great use case.

  8. SteveL-MSFT commented on Oct 24, 2018

    @SteveL-MSFT
    Member

    I don't think it's Console.ReadLine itself that is slow, but the ReadLine loop in ConsoleHost that is slow. It's single threaded and does a bunch of processing per key press.

  9. changed the title [-]Read-Host consumes input much more slowly than regular terminal[/-] [+]Enable pwsh ReadLine to use PSReadLine[/+] on Jun 10, 2020
  10. SteveL-MSFT commented on Jun 10, 2020

    @SteveL-MSFT
    Member

    It's been brought up that when pwsh prompts for mandatory parameters, the experience is not great and typically users ctrl+c and retype the command with the parameter to get tab completion. We should support using PSReadLine for prompting (which should also cover this read-host case) while still supporting tab completion for a parameter while also resolving the issues Jason Shirk (@lzybkr) brought up above for general ReadLine for strings.

  11. iSazonov commented on Jun 11, 2020

    @iSazonov
    Collaborator

    A tracking issue in .Net Runtime repo dotnet/runtime#800

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performanceWG-Interactive-Consolethe console experience

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions