Open thowi opened 4 years ago
Hi, have you tried disabling automatic widget re-binding? It might be what you’re looking for. https://github.com/zsh-users/zsh-autosuggestions#disabling-automatic-widget-re-binding
Hi Eric,
That indeed solves the problem! Thanks for the tip!
Wondering why this is not the default? The docs say "you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run _zsh_autosuggest_bind_widgets". I would assume that changing the widget lists (myself or by other plugins) is a corner case (I might be wrong). So why optimize for a corner case and make the average case slow for everybody?
If I change the widget lists myself, I can call _zsh_autosuggest_bind_widgets. If a plugin changes them, it should also call _zsh_autosuggest_bind_widgets.
Cheers
Wondering why this is not the default?
The idea was to make it "just work" for all users. And more sophisticated users can take matters more into their own hands if they want.
I would assume that changing the widget lists (myself or by other plugins) is a corner case (I might be wrong).
It might be a corner case. We unfortunately don't really have any data one way or the other, so we'll have to make an educated guess. I think I'd be open to changing the default behavior if a good case can be made for it. If we go that route, we can bump the minor version and have people let us know if it breaks things for them. We can always revert back if enough people are inconvenienced.
Makes sense. For me personally, though, "just work" includes performance as well. Hard to tell what would be considered a bug by more users: a) Slow zsh-autosuggestions. b) Possibly stale widget lists. For me a) was a bug (hence I filed this), while I didn't even know about widget lists. I don't know the average user though.
For me a) was a bug (hence I filed this), while I didn't even know about widget lists.
The problem is that "possibly stale widget lists" can manifest in actual user-noticeable bugs like not getting any suggestions if e.g. plugins are not sourced in a precise order.
I think you're right, performance is important. I'll leave this open so we can further look into disabling this behavior by default. It's been a while since I've looked at this, so I'll have to dig in deeper before I can comment more.
Here's some maybe-relevant history for future discussion:
zsh-autosuggestions doesn't only add lag on opening, it also makes the whole terminal experience sluggish. Every time I type something, I have to wait for characters to appear. Same when hitting Backspace, it takes twice more time when zsh-autosuggestions is running. The whole terminal takes a big performance hit
Describe the bug
I'm using the Powerlevel10k theme and Antigen for loading plugins:
I noticed that my prompt get slower with zsh-autosuggestions (i.e. just hit return in the Terminal has a noticeable lag). So I benchmarked this with https://github.com/romkatv/zsh-prompt-benchmark and got this: Without zsh-autosuggestions: ~60 ms per prompt. (average over 3 runs) With zsh-autosuggestions: ~267 ms per prompt. (average over 3 runs)
So clearly, this adds a significant lag.
I also profiled my prompt using the instructions at https://xebia.com/blog/profiling-zsh-shell-scripts/ and found out that especially
_zsh_autosuggest_bind_widgets
is taking up a lot of time.To Reproduce
Enable zsh-autosuggestions. Hit enter in the terminal.
Expected behavior
Fast.
Desktop