-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Slow speed of cd #136
Comments
Does this happen for only Right now, I'm using the following to suppress it: # Start the autosuggestion widgets
_zsh_autosuggest_start() {
_zsh_autosuggest_check_deprecated_config
_zsh_autosuggest_bind_widgets
add-zsh-hook -d precmd _zsh_autosuggest_start
} This operates on the assumption that the list of ZLE widgets will not change after the shell has been setup. If they do, then you could potentially end up without suggestions. (Although, as far as I know, nothing apocalyptic will happen.) See if this works for you. I'm considering filing a pull request, but managing multiple parallel PRs is a pain and #134 is still open. |
@pytnik89 please try branch fixes/remove_precmd_after_init and let us know if that solves your problems with midnight commander. |
@PythonNut Thx for u async fix, it seems to work as fast as many cores I have(particularly, I spend 3 sec. to enter in directory with async against 12 sec. without it) , but ... The problem is still exist. |
This might be related to what I reported back in the #108. |
@balta2ar, can u give more details about u issue with mc, may be it's the same... |
@pytnik89 I had tried to reproduce the issue on a clean Ubuntu 14.04 in Vagrant but couldn't. The problem did not reappear. However my two machines (ArchLinux and Ubuntu 12.04) are suffering from that issue. Back then I disabled autosuggestions and wanted to dig into my zshrc and binary search for the culprit. Unfortunately, I didn't get to do that since. Hopefully, I'll give it another try soon... |
@balta2ar can u dig into dirictory tree as deep as possible, does it become too slow?(I'm using arch) |
@pytnik89 Right now I'm on Ubuntu 12.04 and yes, it's getting way too slow. I confirm that. I've also tried the branch and it didn't help: zsh-autosuggestions → git rev-parse HEAD
316ea3ecd6efec02de79380bed5149531b448603 |
@balta2ar so we have the same issue, and I have no idea how to solve it, because of reason that I mentioned above. |
@pytnik89 I've just tried on ArchLinux. For some reason cd in mc even without autosuggestions is not blazingly fast, but with it it gets way, way much slower. The initial slownes may be due to a number of addons that I use, for example |
Well, delays are accumulating... I tried two more variants:
|
I'm also experiencing a slow prompt on Windows using babun. I can just keep any key pressed for 1-2 seconds, once I release it the prompt is still catching up spitting out characters... really annoying. I have to disable the plugin until this is fixed. |
There are several complaints about mc being slow with zsh on dir change, e.g.: https://www.midnight-commander.org/ticket/2072#comment:20 Unfortunately solutions that are mentioned do not help me (things like disabling $TERM=xterm256-color, removing zsh history). I know very little of zsh and I'm not sure how to profile it. How do I root cause this issue? I can only repeat myself that even without autosuggesions cd is slow. I looked at my preexec, precmd functions: → echo $preexec_functions, $precmd_functions
_zsh_highlight_preexec_hook, _z_precmd _mc_precmd I probably need to go deeper into them. |
I also have to mention that cd in |
Another experiment that I've performed is to leave minimal zshrc with enabled autosuggestions. Without mc cd is fast. With mc it is suddenly terribly slow. I wonder what could mc be doing that it slows down cd THAT much... |
Some more findings from my side. I've put code like this into autosuggestions to measure execution time: _zsh_autosuggest_strategy_default() {
start=$(date +%s.%N)
local prefix="$1"
# Get the keys of the history items that match
local -a histkeys
histkeys=(${(k)history[(r)$prefix*]})
# Echo the value of the first key
echo -E "${history[$histkeys[1]]}"
end=$(date +%s.%N)
echo "`date +%s.%N`: _zsh_autosuggest_strategy_default: `echo \"$end-$start\" | bc`" >> /tmp/auto.log
} And I noticed that this function is called on every keystroke. When you're typing things in console, it's not much individually:
However when I entered this directory in mc: My current assumption is that mc sends this long path character by character... Maybe I need to dig into mc source. |
Interesting. That would make sense. If so, this issue may be similar to #141, and may be solved with something like #134 or #148.
You might find Thanks for your work! |
I've been reading issues related to slow pasting and this fancy zsh's bracketed-paste-magic. Do I get it right that if mc took advantage of bracketed-paste-magic escape codes and emulated paste while sending commands to zsh over pty, we could see performance improvements? May that be true, at least in theory? Speaking more concretely, supposing mc is sending something like this to zsh: The solutions you have suggested are certainly worth considering, however, to my opinion, they are plugin-specific. It occurs to me that this "service" communication with zsh that mc is performing under the hood should not be handled in the same way as plain user input by typing. At least with regards to interpreting every character as a separate keystroke. What do you think? EDIT: mc sends things like this to zsh:
|
In this commit (https://github.com/balta2ar/mc/commits/f17ebb89791ce5ff64608929f62658fa04f4556d) I did a quick-and-dirty hack to check whether using zsh bracketed paste magic can help. Basically I just send 1. Make sure you have these lines in your
|
@balta2ar, of course I will send this |
@balta2ar, I did, It's still thoughtful...may be a little bit faster... But thx. It's better to look into src of mc to find out the solution. |
I've tried this pull request: #134 |
Recently merged #178 may be a helpful workaround here. Check out the develop branch for now until v0.3.3 is released |
Thank you! I think I've already mentioned that somewhere else, but just to disprove my statement from 23 of May in the same thread, async really does make a difference. I think that could be a great addition to #178. |
Adding more cross references here. I mentioned this issue in rupa/z, as you can see. I just wanted to show some more numbers: rupa/z#191 (comment) The test that I described in the above mentioned issue took 4.459800 seconds when z and autosuggestions are off, and 8.59920 seconds when async branch of autosuggestions is on. Later I measured sync branch (master) and it's 1:45.61 (1 minute, 45 s, not reported in the issue). Basically, there is almost nothing new, but I wanted to ask whether it's possible to offload more work into background, to shrink that gap between 4.459800 and 8.59920? @ericfreese @PythonNut |
@balta2ar Out of curiosity, have you tried the new
I'm not sure about offloading more work into the background, but I've been thinking we could probably do some more optimization. For example if you've typed "e" and the suggestion is "echo hello" and then you type a "c", there's no need to recompute the suggestion, just use the suggestion from last time. Additionally, if you've typed an "e" and there's no suggestion, when you then type a "c" there's also no need to compute another suggestion. Since there was no suggestion with "e" you're guaranteed to get no suggestion with "ec" |
@ericfreese I've just tried it and new shell at startup prints:
What you say totally makes sense. Moreover, Trie is a perfect candidate for such a task. Are you going to implement something similar? One thing that bothers me is the order, though. As far as I get it, more recent items from history have preference to be suggested. This somehow needs to be accounted for during the trie construction and item retrieval. Keeping in mind the fact that history rarely gets deleted (I suppose that's true across most users), we rarely need to reconstruct the trie. Most of the time we need to track the addition of a new history item and add it to the trie. Maybe there is a way to do it efficiently. Background task that contains this trie can serve many shells at once. |
Ah, yeah it currently only works with 5.2.
I wasn't planning on implementing a trie, though I think it might be a good data structure for zsh to implement under the hood (and who knows, maybe it already does). I want to try as hard as possible to avoid managing a separate copy of zsh history since there are so many history options we would then have to support. It's easiest if we can just delegate the tasks dealing with history to zsh builtins like |
I've quickly grepped "trie" and "tree" and I haven't found anything related. Maybe they name it differently though.
Doesn't using suggestion from the last time imply that you have some kind of a local copy of the history? It might be reduced though. I'm not sure what's the bottleneck is at the moment, but I pictured the algorithm as follows. When a user types the first character, you retrieve the whole (or part of, depending on the configuration) history. Then you construct a data structure that allows for fast filtering. Whenever user types/deletes a character, you query that data structure to obtain new suggestion. We're storing a copy of a history only for the purpose of faster filtering and only while user in typing something in. We do not store it across different command line executions/shells (yes, this is contrast with what I described before because I think it's simpler and may be enough in terms of performance. Just another approach). I'm just curious how you see this and how you're gonna implement it. |
Hi Guys, |
@Memphizzz Did you find a solution that works to speed this up when using babun on windows? |
@ralberts Not really, no. I switched to fish which has auto completion by default. |
FYI: Babun on Windows is basically just mintty running Cygwin's zsh. I'm getting this while running zsh under ConEmu (under the Cygwin/msys connector so I get proper ANSI support). Since this build of zsh uses Cygwin, |
I'm hoping that the asynchronous suggestions just merged into the |
Thank you very much for your work, @ericfreese! I've just checked out Besides, when I bring console in mc by pressing Ctrl-O and run any command after traveling across directories for some time, I get this printed after the command output:
EDIT: On top of that I notice high zsh's CPU usage. |
Thanks @balta2ar 😄 I will look into those error messages tomorrow. |
Ok @balta2ar, I've pushed up a few commits that I believe fix the issue causing those error messages. Please give it another shot when you have time. Thanks again for your patience and taking the time to try this new stuff out. It's super helpful 🍻 |
Wow, not only errors are gone, but I also feel that delay on directory change in mc is noticeably smaller! I'm not saying it's perfect, I can still create a rather artificial example of highly nested directories (mentioned here #136 (comment)) and it starts to get slower there, but it's definitely better for my practical day-to-day use cases (comparing to what I saw in the morning today). Thank you for your efforts, @ericfreese! I appreciate it very much! On a side note, and out of curiosity, do you still plan to have optimizations you mentioned above: #136 (comment)? I think having them along with async would be amazing. |
Awesome!
I've implemented the first half of that on
I think we do still try to fetch a suggestion on every keystroke if there was no prior suggestion though, so that could probably be optimized a bit further. I'll try to get that in for |
Just noticed: when I type
|
Ok, should be fixed with c9a51e0. Thanks! |
After initialization of zsh-autosuggestions the speed of change dir in Midnight commander(regular movements in mc) dramaticaly falls down. I use oh-my-zsh zsh version - 5.2. Is there way to solve it?
The text was updated successfully, but these errors were encountered: