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

Typying laggs due to slow completion #17

Closed
weilbith opened this issue May 6, 2020 · 22 comments
Closed

Typying laggs due to slow completion #17

weilbith opened this issue May 6, 2020 · 22 comments
Labels
bug Something isn't working

Comments

@weilbith
Copy link

weilbith commented May 6, 2020

Hey,
thanks again for this plugin! 🙏

I use it now just my second day, but what really bothers me are the lags. This is especially the case for paths. Each time I enter a slash it starts to lag. I guess this will apply for all completions that are not optimized or simply slow.
I must admit I have rarely a knowledge of such things in Zsh, but is is possible to do asynchronous completion? As much as I like this plugin: this is a no-go for me at the moment. Maybe I need to disable completion sources that are slow. I don't know.

@marlonrichert
Copy link
Owner

marlonrichert commented May 6, 2020

Can you give me an exact test case where the completion feels particularly slow? Then I can try to reproduce it and figure out how to speed it up.

For me, path completion feels very snappy. I have not noticed any problems with it. On the other hand, I find that completing certain git commands can feel slow sometimes.

@marlonrichert
Copy link
Owner

I must admit I have rarely a knowledge of such things in Zsh, but is is possible to do asynchronous completion?

I have tried to do that using https://github.com/mafredri/zsh-async/, but the problem with async completion is that if the completion finishes when the Zsh Line Editor is no longer active, it simply will not update. So, basically, while typing and then you pause, the last couple of letters fail to trigger completion. It only worked as long as I kept typing, which didn't feel quite right. 🙂

@weilbith
Copy link
Author

weilbith commented May 6, 2020

Hmm okay it is my fault. Sorry for your inconvenience. It happens when my PC is under load. But is is quite "interesting". So it happens already when I run some simulations for work. but actually these just increase the CPU usage to ~30%. But doing more "tests", I recognized that this only happens for special cases. So I use TMux. So if I'm in a TMux window (I hope you know the terminology, it is like a terminal tab or a virtual desktop) and have the simulation running in one pane (like a window on a virtual desktop) and them simply do like cd ~/ in another pane along the simulation, it lags on each slash. Open/switch to a TMux window without the simulation it is smooth. So it is not the fault of this plugin. Probably this is a general issue, but this plugin makes me feel it more directly. Super weird behavior. No clue where to start debugging this. 🙈

@weilbith weilbith closed this as completed May 6, 2020
@weilbith
Copy link
Author

weilbith commented May 6, 2020

But sad in general about the async stuff. Always nice to have it. :/

@marlonrichert
Copy link
Owner

But glad it's not a problem in my plugin. 😉

@marlonrichert
Copy link
Owner

Reopening, because @Mallchad reports the same problem.

@marlonrichert marlonrichert reopened this May 14, 2020
marlonrichert added a commit that referenced this issue May 15, 2020
@marlonrichert
Copy link
Owner

@Mallchad The problem was that zsh-autocomplete wasn't expecting AUTO_CD to be enabled and no matches were generated when you typed a directory in the command position. This should be fixed now. In addition, I've added some enhancements to the way directories and files are presented in the completion results. Please update and check it out. 🙂

@Mallchad
Copy link

It does indeed feel less laggy, although, it does not seem to be gone entirely.
Namely, if I misspell any character it starts to lag again when completing a path.
So I assume this is due to some kind of completion timeout with directories.
But only (as far as I can tell) when you have the direction on it's own without other commands in front.

@marlonrichert
Copy link
Owner

Thanks, I’ll investigate.

@marlonrichert
Copy link
Owner

@Mallchad I cannot reproduce it. When you make a misspelling, what do you do next? Do you just continue typing? Can you give me an example of a misspelling plus what you typed afterwards that made the completion slow?

@Mallchad
Copy link

I usually have typed out a whole word / command by the time I have a chance to process the fact that I've made a mistake, but current it is made painfully aware to me that I've made the mistake because if I ignore, or don't realize the popup that is telling that I made a mistake.
Even if I put 1 character wrong sometimes it blocks input for a few hundred miliseconds.
This ONLY happens if it can't find any candidates though.

marlonrichert added a commit that referenced this issue May 17, 2020
@marlonrichert
Copy link
Owner

@Mallchad All right, I pushed in a new fix. You now get error correction on any path you type whenever you type a /. Please update and let me know how that's working out for you. 🙂

@Mallchad
Copy link

This does seem to improve things quite a lot.
Thanks man.
But, I think this is still a hack to the symptom, rather than tackling the core issue.
I still notice that the error popup occurs, although it's quite a lot less bad when the "magic-slash"
autocorrects because it stops once the candidate has been completed successfully.
Peek 2020-05-17 14-00
This shows some of what I'm seeing, again, when it can't find completion candidates sometimes
(but not always) there is noticeable lag that can mess typing up.
This is most notable if you type one of the earliest characters wrong and the prompt lags because
either you or the magic-slash gets a chance to try and completing it which can mess up successive
keystrokes.
Thanks again for the fast responses and fixes :)

PS
I had to force myself to not reflex tab complete and purposefully make errors just to get that click D:

@marlonrichert
Copy link
Owner

@Mallchad I watched your video several times, but I cannot tell the difference between you stopping with typing or the system lagging. 🙂 Can you please tell at which points exactly you experienced lag? With which inputs did the system get stuck? And what were the completions offered afterwards?

@marlonrichert
Copy link
Owner

Rather than post a video, I'd prefer if you could just type some test cases for me. 🙂

Like: "Given directory structure A, when I type B, the system hangs. Then, when the system resumes, it outputs C."

@Mallchad
Copy link

If am looking for, say a binary in /home/mallchad/.local
I might type /home/nallchad by mistake.
With the magic slash it will successfully complete (because it's the only completion).
However, after I've hit the n key the small delay has kicked in, that can throw me off.
Another example.
If I type man
then hit space, it then defiantly hangs (probably because it's 20,828 completion candidates). -It seems like it's supposed to cache candidates but I'm not feeling it.
Another example.
Say I want to delve into my desktop applications
I might type /usr/share/applacations
if I hit one wrong key in that wrong word I get the red text that flickers when I type and delays me seeing the result.
The biggest thing I notice is if I (naturally) try to backspace to correct my mistake, then it hangs really quite bad, making it hard to correct my mistake. (I could trust in the magic-slash but I'm 100% on board with that kind of completion :) ).

-Side note
I do have a very high refresh rate monitor so the apparent slowest it way more visible to me than it would be to most people.
*sometimes I see delays that are in the tens of milliseconds range, but that I can tolerate.

@marlonrichert
Copy link
Owner

Thanks for the detailed description! I still cannot reproduce it at all, but now at least I have some idea of how to fix it. 🙂

@marlonrichert
Copy link
Owner

@Mallchad I pushed in a new fix. Please try it out and let me know if it works. 🙂

@Mallchad
Copy link

@marlonrichert this is more than good enough.
I still think that it might be possible to do async, and this would be the best final result.
But this is very good for me now, I won't ask this of you, it would require a lot of rethinking.
Thank you for all your hard work 🎉

@marlonrichert
Copy link
Owner

You're welcome! 🥳

I actually tried to implement asynchronous completion at some point, but it was very buggy —and not actually any faster. 😂

My current code does the automatic listing in a different way, though, than originally. So, I might give it a try again at some point. 🙂

@marlonrichert
Copy link
Owner

I do have a very high refresh rate monitor so the apparent slowest it way more visible to me than it would be to most people.

@Mallchad How does this impact the performance of your shell? Is the shell refreshed each time your monitor refreshes?

@Mallchad
Copy link

Ok, 1, asynchronous doesn't actually have to be faster to make a difference, it just needs to be non-blocking. ie, usually laggy behavior is because something is hanging up the process you're concentrated on.
-You want typing to update but it's being preventing be completion generation.
2, it's not that my monitor impacts performance, it's that I have more that twice the opportunity to (frames) to notice any delay. Where at 60fps I have maybe 16ms to see any lag for any given frame. 160ms for 10 frames.
For a 144Hz monitor it's more like 6-8ms.
There is a small flickering, and I noticed it with https://github.com/zsh-users/zsh-autosuggestions
and I actually disabled it for now (not that worried about it)
But now that I think about it it may be because you were causing the display to refresh a lot, which makes sense because you need to update the completions every character that's typed, but I wonder if the refresh is taking longer than it needs to.
I don't doubt some of it is quirks with the zsh library an the other half is your plugin.

@marlonrichert marlonrichert added the bug Something isn't working label Mar 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants