Repository navigation
Description
ble version: 0.4.0-devel3+0506df2
Bash version: 5.0.17(1)-release, x86_64-pc-linux-gnu
Hi. This project is great.
Basically I'm having performance issues, there is a perceptible delay between my key strokes and the letter appearing on the screen. Is this something that should be expected ? I'm currently under Ubuntu 20.04 on WSL2. I'm coming from zsh and I would really love to use bash, but syntax-hightlight and autocomplete features like the ones you provide are a must have. However performance issues are a deal breaker.
I see there are other open issues related to performance, but I saw they were more specifically related to autocomplete or some other features. Please let me know if I should close this and continue the discussion in those open issues.
Summary
(Edited by @akinomyoga)
Here I summarize the discussions made here. There can be various causes that slows down the response in WSL2. Depending on the actual bottleneck in your environment, maybe you can take the following workarounds.
Remove slow Windows filesystems on /mnt from PATH
It is known that the Windows filesystems mounted on /mnt is very slow microsoft/WSL#4197. When PATH contains directories under /mnt, the completion becomes slow. One solution is to remove /mnt/* from the environment variable PATH:
From #96 (comment)
If you are fine with removing all the Windows paths from
PATH, you can just put the following command in yourblerc:ble/path#remove-glob PATH '/mnt/*'
Another solution is to configure wsl so that it doesn't include Windows paths in the environment variable on the startup of the shell:
From #96 (comment)
You can also create a file called
/etc/wsl.confand put this:[interop] appendWindowsPath = falseMore info can be found in WSL's docs here.
Integration with bash-preexec to remove the overhead of DEBUG trap
This has been solved by introducing a proper support for the integration of ble.sh and bash-preexec. When bash-preexec is loaded, ble.sh automatically detects it and properly communicate with the loaded bash-preexec. Please just update ble.sh to the latest master. See also #96 (comment).
Disable auto-complete
If the above settings does not work, maybe you can turn off auto-complete or set a delay for auto-complete.
From #96 (comment)
$ bleopt complete_auto_complete=[...] you can configure bleopt complete_auto_delay (the delay of auto-complete) so as to reduce the frequency of auto-complete, e.g.,
# blerc bleopt complete_auto_delay=300
Activity
akinomyoga commentedon Apr 5, 2021
Thank you. OK, I have set up WSL2 with Ubuntu 20.04 LTS and could reproduce the small delay even after disabling
auto-complete(although the delay is almost unnoticeable in my environment). It seems that the plain Bash doesn't have the delay in WSL2. I don't see the delay either in Cygwin or genuine Linux systems. This must be related to some characteristics of WSL2.I'll take a look later, but I'm busy recently so would appreciate it if you could narrow down the bottleneck. Thank you!
[-]Performance issues[/-][+][WSL2] input delay[/+]jmeder0s commentedon Apr 5, 2021
I kind of narrowed it down. It turns out the delay only happens (or at at least is most noticeable) when I type the very first character after starting my terminal session, subsequent keystrokes appear to behave normal. In addition this only happens when I override some settings in the blerc file. Particularly I'm changing the syntax highlight colors, so my blerc file only contains a bunch of calls to
ble-color-setface. Please let me know if this makes sense.akinomyoga commentedon Apr 5, 2021
I'm not sure, but this is possibly related to
auto-complete. Is the delay still present after disablingauto-completeby the following command?If it is the delay by
auto-complete, you can configurebleopt complete_auto_delay(the delay ofauto-complete) so as to reduce the frequency ofauto-complete, e.g.,# blerc bleopt complete_auto_delay=300Ah, OK.
ble.shdefers the initialization of faces until it is first required. It seems the deferred settings of faces takes some time in your environment. I'll check it later.jmeder0s commentedon Apr 5, 2021
Oh I see. If ble.sh defers the initialization of faces until it is first required, then that would explain the problem. There are a lot of calls to
ble-color-setfacein my blerc file, so if they are all run once I type for the first time, we should expect the delay. Is there any way to tweak tis behaviour, maybe some kind of flag or config to make ble.sh evaluate calls toble-color-setfacewhen blerc file is sourced ????rashil2000 commentedon Aug 28, 2021
Hi @akinomyoga!
I was about to open an issue related to performance in WSL2, but I saw that this is already open. I'm facing issues too. I'll try to elaborate.
While auto-complete and auto-suggestions work fine, there's a very perceptible lag on input (delay between typing and characters appearing). I'm on a laptop, so power consumption might be interfering with how snappy the input is. Therefore I've tried to record on both battery-mode and plugged-in mode.
battery

plugged-in

Both these have very perceptible lag, but the typing is slightly more responsive in plugged-in mode. I have only 3 lines in my blerc
Note that this lag doesn't appear in WSL2 at all (whether on battery or plugged-in) in zsh, pwsh or vanilla bash.
akinomyoga commentedon Aug 29, 2021
@rashil2000 Thank you for the information!
First, I need to note that
ble.shis different from the normal line editors of the shells which are implemented in the compiler languages such as C and C#, so the performance difference is inevitable. In particular, when the computer is slow, there might be nothing that we can do. Nevertheless, if you could point out the bottleneck ofble.sh, I'm not reluctant to improve it, but generally, performance issues wouldn't be completely resolved in slow computers as far asble.shis implemented in Bash script.In your case, I'm not sure if there is any bottleneck that significantly worsens the performance, or just the entire processing takes a long time in the battery mode, but I might do something in the former case. I implemented
ble.shso that theauto-completedoesn't interfere with the user input processing, so there are two possibilities: 1) the bottleneck lies outside ofauto-complete, or 2) the user-input detection becomes slow in the battery mode. I have related questions:$ ble-measure -a 50 'ble/util/msleep 10auto-completeand other background processing, does the response in the battery mode change?rashil2000 commentedon Aug 29, 2021
I have a gaming laptop [Specs: i7-8750H, 6 cores (12 threads), 16GB RAM, GTX 1060 GB graphics]. I don't think the system is a slow one. In any case, to completely eliminate any possibility of doubt, I conducted an elaborate experiment. I created 2 virtual machines, both running Ubuntu:
In both these VMs,
ble.shruns buttery smooth - no input lag/latency. Note that they're not particularly heavily-specced VMs. This leads me to believe that the performance is certainly not able.shissue. It almost exclusively occurs on WSL (and sometimes MSYS2, or even Termux (Android)). However, the amazing features ofble.shhave spoilt me, and I would like to use it everywhere possible (which includes WSL2, albeit with some workarounds, if possible).No effect
Very slight improvement
akinomyoga commentedon Aug 29, 2021
Thanks for the information and answers. From these answers, it seems that the delay is caused by somewhere not related to the auto-complete or syntax-highlighting based on the filenames. Another possibility that causes the delay is the access to
/tmpwhich is a RAM disk on many Linux distributions but is not in WSL2 by default.$ ble-measure -a 5 'ble/util/assign a "echo $((b++))"'I have also tested with WSL2 in my environment. It seems that I also have a very small delay with WSL2 (though I'm not sure if this is the same issue as the one that you observe). I tried to figure out the cause of the small delay, but I found some strange behavior: While I observe the delay when I open the WLS2 through the "Ubuntu 20.04 LTS" icon in the Windows start menu, it seems that I don't have the delay if I connect to the WSL2 through
sshfrom Cygwin.The terminal that opens up by the start menu icon seems to be actually the command prompt (at least the property window which can be opened from the shortcut menu of the window icon is that of the command prompt). Maybe the delay is related to the terminal or some interface of the connection between the WSL2 subsystem and the Windows subsystem.
ssh, do you experience the same delay in the battery mode?rashil2000 commentedon Aug 29, 2021
I start it using the
wslcommand. This is the same command that the Start menu shortcut uses. It is the recommended way of starting/stopping/managing WSL distributions.I don't have Cygwin set up on my machine, but I could install
opensshon MSYS2 (pacman -S openssh). But since Windows 10 already comes with the OpenSSH client pre-installed (at C:\Windows\System32\OpenSSH\ssh.exe), I used that. Surprisingly, I experience zero input lag as you described, even on battery mode. Ble.sh runs buttery-smooth.It's definitely an issue with the
wslcommand. However, there are a few points to note:wslcommand, Windows sets up some useful variables inside the WSL2 shell, like these:They are particularly useful for detecting if you're on WSL for generic linux apps/scripts. When using
ssh, they don't get set.rashil2000 commentedon Aug 29, 2021
Needless to say, the disparity between
wslandsshis huge (although ble.sh is the first application where I've observed this).Do you think I should report this in the official WSL repo (citing this issue as source)?
akinomyoga commentedon Aug 31, 2021
OK, thank you for your information. As you have experienced the zero delay with
ssh, the delay that I observe in my system seems to be the same issue with yours. I'm not sure if we can do anything from theble.shside, but as readline and Zsh Line Editor don't share the issue, maybe some specific operation thatble.shuses is slow with thewslconnection. I will later test it in my environment.Currently, the issue is not so clear, and I think they are so busy that they don't have time to investigate such an obscure issue that "some specific application is slow in some specific situation". I'd think the issue would be just ignored at best (unless there are reports from many different people on the same issue with ble.sh which is not likely).
We may report it only after we have identified what specific operation causes the delay of
wsl.rashil2000 commentedon Aug 31, 2021
Okay, I understand that.
Thank you for your help so far and the
sshtip!rashil2000 commentedon Sep 3, 2021
Okay, I somehow missed this, but I changed my default shell in WSL2 to zsh, and I can observe the same input delay in zsh, when launched through the
wslcommand. The delay is absent throughssh.Though I could observe the difference only in battery mode, there's definitely something wrong with the
wslbinary.14 remaining items
SuperSandro2000 commentedon Jan 23, 2022
I think most of the delay came from
history -a; history -c; history -r.wezterm needed to be modified anyway since it always loads bash-preexec and vendors it.
akinomyoga commentedon Jan 23, 2022
Hmm, didn't it work without the modification? In the above integration, I intended to make
ble.shwork with existingbash-preexec.shwithout modifications; the above integration doesn't include the code ofbash-preexecbut communicates with the existing code when it is loaded.If the integration doesn't work without wez/wezterm#1572, it means thatbash-preexecbundled withweztermis actually a different implementation fromrcaloras/bash-preexec?I have now checked
bash-preexecembedded inwezterm. I haven't really checked by runningwezterm, but I think it will properly work because the following conditions are met:__bp_importedexists.__bp_install_stringexists.PROMPT_COMMANDprefix is the same.PROMPT_COMMANDsuffix is also the same.Edit: I now tried
weztermandwezterm.shof wezterm/wezterm@3cc26cc (before wez/wezterm#1572) and wezterm/wezterm@78ea214 (after wez/wezterm#1572). Bothbash-preexecworks fine though both wezterm integration seems to have some problems.It is unrelated to the wezterm shell-integration, but I faced another problem with
weztermandble.sh. Somehowble.shseems to fail to reset DECSTBM inweztermand the scrolling region is restricted in the first two lines with a certain condition. This happens afterbleopt prompt_status_lineis cleared. Note that the problem does not arise in other terminals.SuperSandro2000 commentedon Jan 23, 2022
So far it seems to work but I think it would be easier if I keep the patches for atuin and wezterm to remove a whole bunch of fragile bash code. I could imagine that the removal functions break which would be a bit of a pain to debug.
I was referring that the patch is still required when I want to use the hooks without the preexec compatibility stuff.
I must admit I wasn't using wezterm terminal in the last weeks but only the shell functions. I intent to use it again in the future especially because Windows Terminal breaks tmux panes and splits.
akinomyoga commentedon Jan 24, 2022
Ah, I see your point. Then let's keep the special treatment in
wezterm.sh. By the way, the special treatment inwezterm.shonly works when it is loaded afterble.sh. Ifwezterm.shis loaded first and thenble.shis loaded, the integration byble.shwill be turned on.Actually, what I have implemented in the integration is the switching between the DEBUG trap and the blehook in either direction. This is needed for
bash-preexecto work even afterble.shis detached byble-detach(which is currently undocumented in the manual, but only found inble --help). Whenble.shdetaches,ble.shletsbash-preexecreinstall the DEBUG trap. But, considering that it is rare to detach fromble.sh, maybe it is fair to completely removebash-preexecimplementations.I have fixed the issue of DECSTBM in 4b1601d.
Digression: Some detailed story of DECSTBM
This above problem is related to the supported terminal sequence for clearing
DECSTBM. The DECSTBM escape sequence has the form\e[...r. However, the escape sequence terminated byris designated as the sequences for private use by ANSI X3.64 and ECMA-48 so heavily conflicting with other escape sequences defined by terminal vendors and terminal emulators. Currently, most other escape sequences are not used anymore, but there is one escape sequence conflicting with DECSTBM, i.e., SCORC\e[rwhich is used by consoles and terminal emulators in SCO OpenServer. Some terminals distinguish these two different escape sequences by the number of arguments, so that\e[;ris clearing DECSTBM and\e[ris performing SCORC. Some other terminals only support DECSTBM and thus accept both forms\e[rand\e[;ras clearing DECSTBM.kittyandweztermsomehow only accepts\e[r, which means that they only support DECSTBM and, in addition, they fail to ignore extra CSI parameters. So far I have recognizedkittyfor this behavior, but now I realized thatweztermalso behaves in a similar way. I have newly implemented the test for the terminal to check which form of the escape sequence the terminal supports for clearing DECSTBM.I recognize another layout issue with
wezterm.shshell-integration (even withoutbash-preexec). Some extra empty lines are inserted between the prompts. I'll later work on the problem.*Edit: This was easier than I though. I fixed it in e199bee. In order to use it with
wezterm.shshell-integration, one needs to put the following setting:# blerc bleopt prompt_command_changes_layout=1SuperSandro2000 commentedon Jan 24, 2022
I need to do it from time to time because nix-shell is still not working like it should. I will write you another comment into the other thread.
akinomyoga commentedon Jan 24, 2022
OK, thank you for the information! Please feel free to open a thread.
refparo commentedon May 13, 2024
Hello. On the problem with
PATH, is it possible for blesh to use a differentPATHto calculate the completions? I still wantexplorer.exeand other programs from Windows to be accessible from WSL.improve performance on WSL2 akinomyoga#96
akinomyoga commentedon Sep 22, 2024
@refparo @mgastonportillo @heathprovost I've been believing that the issue of the slow filesystem should be fixed in the upstream WSL2 system, but it doesn't seem to be fixed there. I decided to accept a workaround contributed by @musou1500. Now, in the
masterbranch, when the completion is performed in WSL2 withPATHcontaining/mnt/*, ble.sh generates the command names in a background process so that the completion doesn't block the foreground shell. This should significantly improve the situation of the slowauto-completein WSL2 (though there might still be places affected by the slow filesystem apart from the completion).refparo commentedon Sep 23, 2024
Thank you a lot! But actually, I believe that even on native Linux, if the PATH contains a FUSE-based filesystem, there would likely be a performance issue as well. It would be even better if a customizable option is added.
cyberalt1 commentedon May 7, 2025
The biggest issue with ble.sh so far. The lag is extremely slow compared to native bash, night and day difference. 100% of development work should be focused on resolving this issue because otherwise ble.sh is unusable.
akinomyoga commentedon May 7, 2025
The system dependence is large. Honestly, I've never experienced a performance issue with Linux (except for unusual cases with e.g. a directory with several tens of thousands of files).
Of course, the performance of a line editor written in Bash cannot be comparable to that of Readline written in C. It is impossible. However, it's not important to make it comparable to the C implementation. Here, what is important is that the absolute delay of
ble.sh(instead of the delay relative to the C implementation) would be a reasonable one for daily use. Currently, it seems to be fine in most systems.It is already the primary concern in the development---Well, I should say the primary is portability, which is the reason that
ble.shis written in Bash instead of C. Then, the performance is secondary.---I've already put a lot of effort into the performance. I'm pretty sure that the current performance is almost the upper limit for the general case. There may still be room to improve the performance for specific cases by identifying the cause, but it is hard to identify the cause for delays that cannot be reproduced in my environment.akinomyoga commentedon May 7, 2025
If you want to solve the performance issue with your environment, please consult the page Performance · akinomyoga/ble.sh Wiki, if you haven't yet checked it.
tjallingt commentedon Oct 1, 2025
I'm using 1password with WSL which relies on
ssh.exesee https://developer.1password.com/docs/ssh/integrations/wsl/Unfortunately
ssh.execannot be executed anymore when using theble/path#remove-glob PATH '/mnt/*'configuration.Without that configuration ble.sh is really slow on WSL, even with that configuration it introduces some input lag.
SuperSandro2000 commentedon Oct 1, 2025
I had a similar issue on NixOS WSL and fixed it by adding a a wrapper script in another place in PATH and exceed there the absolute path to ssh.exe.