-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Slowness when pasting commands with bracketed-paste-magic enabled; slowness with zle -U #295
Comments
I cannot reproduce that: when I paste your long Can you reproduce it in Workaround: set |
Hmm, I can not reproduce it with zsh -f + source zsh-syntax-highlighting.zsh.. my zshrc (rest is default ohmyzsh with some aliases): plugins=(
common-aliases fasd colorize colored-man extract command-not-found
vagrant
gitfast gitignore zsh-git-prompt
debian
pip python virtualenv virtualenvwrapper
atom sublime
cabal stack
gradle
valut
zsh-navigation-tools
zsh-autosuggestions
zsh-syntax-highlighting
)
...
# color completions
eval `dircolors`
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
# colors of hilight
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
ZSH_HIGHLIGHT_STYLES[alias]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[builtin]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[function]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[command]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[precommand]='fg=cyan,bold,underline'
# ZSH_HIGHLIGHT_STYLES[commandseparator]='none'
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=cyan,bold' 3 plugins are in custom:
|
The workaround reduced time to about 7 seconds:) |
I investigated more and the line that was causing the problem is:
if I comment it, the problem disappears. |
I can reproduce this: with your highlighters setting, pasting your example text to |
zprof output is basically what you'd expect:
|
Pretty sure this has to do with bracketed-paste-magic. See zsh-users/zsh-autosuggestions#141 |
@ericfreese I can reproduce slowness in |
Breaking out the two
Here, |
@doubleloop Is the behaviour under |
Compute «${#BUFFER}» just once. I haven't measured the effect of this, but it might just avoid a strlen() every time around the loop, which could add up for large ${BUFFER}s. See issue #295.
@doubleloop Can you try this patch? diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh
index 2571b58..ac9b426 100644
--- a/highlighters/brackets/brackets-highlighter.zsh
+++ b/highlighters/brackets/brackets-highlighter.zsh
@@ -52,7 +52,7 @@ _zsh_highlight_brackets_highlighter()
region_highlight=()
# Find all brackets and remember which one is matching
- for (( pos = 0; pos < buflen; pos++ )) ; do
+ for pos in {0..${buflen}} ; do
local char="$BUFFER[pos+1]"
case $char in
["([{"]) Timing data: $ zsh -f
% time (for (( x = 0; x < 1000000; x++ )) ; do done)
( for ((x = 0; x < 1000000; x++ )) do; ; done; ) 1.49s user 0.00s system 99% cpu 1.509 total
% time (for (( x = 0; x < 1000000; x++ )) ; do done)
( for ((x = 0; x < 1000000; x++ )) do; ; done; ) 1.52s user 0.00s system 99% cpu 1.529 total
% time (for (( x = 0; x < 1000000; x++ )) ; do done)
( for ((x = 0; x < 1000000; x++ )) do; ; done; ) 1.59s user 0.00s system 97% cpu 1.630 total
%
%
% time (for x in {0..999999} ; do done)
( for x in {0..999999}; do; ; done; ) 0.87s user 0.04s system 99% cpu 0.909 total
% time (for x in {0..999999} ; do done)
( for x in {0..999999}; do; ; done; ) 0.88s user 0.03s system 99% cpu 0.925 total
% time (for x in {0..999999} ; do done)
( for x in {0..999999}; do; ; done; ) 0.83s user 0.05s system 99% cpu 0.887 total |
Strange.
the issue is there (10+ minutes). When I comment |
Given that it works in You might look into |
@doubleloop I'm almost positive your problem is from With |
Yes, i used |
@ericfreese Thanks for following up To summarize, there are two unrelated issues here:
The first one may deserve an upstream bug report or a FAQ addition here; the second one should be spun off into a separate issue. |
I've been looking at ways to support |
@ericfreese For z-sy-h I plan to ditch the "wrap all widgets" approach altogether, in favour of just using Would this approach work for zsh-autosuggestions? |
P.S. workers/37639 discussed a potential situation in which multiple plugins would want to hook to zle-line-pre-redraw. |
Looks like that could definitely help. As long as it doesn't trigger after every zle widget execution. Looks like it'd trigger after each keyboard interrupt?
Was any code ever merged to address this? Seems pretty important to be able to have multiple plugins hook to it.
How do you plan to support older versions of zsh? Or would you just cut a new z-sy-h major version that requires zsh 5.3+? |
That's how it seems to behave: if widget
No; I believe the issue hasn't been discussed again since that thread. Feel free to raise the matter on workers@ (I don't have time to do so myself at the moment). I don't think it's hard to implement; we simply waited for a use-case to surface.
I don't plan to require 5.3+ yet; I plan to use zle-line-pre-redraw if available and keep the "wrap all widgets" implementation for users of ≤5.2. (That's going to make debugging user reports fun — there will be two different codepaths for years to come — but I don't see a better option.) As to users of zsh-5.1 and latest z-sy-h [who have bracketed-paste-magic but not pre-redraw]... I would try to coexist with b-p-m, especially since it's not a third party widget but part of upstream zsh. I don't know how precisely I would do that. Your By the way, is there an accepted abbreviation for "zsh-autosuggestions" (like "z-sy-h" for "zsh-syntax-highlighting")? |
@danielshahaf Bpm works by intercepting the paste action and calling
Nope! I've just gotten relatively practiced at typing it. Would be nice though. How about "z-asug"? |
I see... so if widget A calls widget B, only the wrapper for A does any work, and it does it after both A and B have finished. I'll keep this issue open to track adding this optimization to z-sy-h. :-) (I might use a global push/pop counter to avoid relying on $funcstack: should be a simple patch to the wrapper function.)
LGTM, it doesn't seem to be a word or an existing trademark. |
testwidg() {
zle -U 'a=; a=${(r:100000::_:)a}; len=${#a}; zshstyle() { repeat 500; do b=${a[-5000,-1]}; done }; zshstyle2() { repeat 500; do b=${a[-5000,len]}; done }; shstyle() { repeat 500; do b=${a: -5000:5000}; done }; time ( zshstyle ); time ( zshstyle2 ); time ( shstyle )'
}
zle -N testwidg
bindkey '^t' testwidg Pressing Ctrl-T causes 4 second delay. That's with recent fork optimization. With |
You raised this on list and Bart speculated it was due to $PENDING not being set: workers/38494. So, to summarise:
This issue should probably be bifurcated. |
is there a fix available? |
According to the commit reference above, there is a clue in some |
Test case: See the first comment of issue #295. Before: num calls time self name ----------------------------------------------------------------------------------- 1) 14 284.67 20.33 82.84% 284.67 20.33 82.84% _zsh_highlight_highlighter_brackets_paint 2) 15 313.72 20.91 91.30% 26.62 1.77 7.75% _zsh_highlight 3) 14 318.68 22.76 92.74% 7.41 0.53 2.16% _zsh_highlight_call_widget After: num calls time self name ----------------------------------------------------------------------------------- 1) 15 57.25 3.82 45.33% 28.30 1.89 22.41% _zsh_highlight 2) 14 81.96 5.85 64.90% 27.02 1.93 21.40% _zsh_highlight_call_widget 3) 14 26.31 1.88 20.84% 26.31 1.88 20.84% _zsh_highlight_highlighter_brackets_paint 4) 2 10.66 5.33 8.44% 8.97 4.49 7.10% VCS_INFO_formats 5) 2 25.92 12.96 20.52% 7.72 3.86 6.11% VCS_INFO_get_data_git (That's not in my everyday configuration but in my minimal testing setup, which runs vcs_info with the default settings.)
In my testing, the bracketed-paste-magic interaction is fixed on the feature/redrawhook branch. (I tested in Sorry for the delay. The branch was lying around for quite a while but I haven't realized that it hasn't been mentioned on this issue yet as a workaround. I also pushed a version of the above As to the |
This is great, thank you for all your work on it. I saw that zsh 5.8.0.3 is required, but my distro has 5.8 as the latest. Do you happen to know if a new version is going to be released soon? |
Thanks for the feedback. zsh upstream has no particular plans for a release at this time. 5.8 is the latest release (there were no 5.8.0.[123] releases; the fourth number is a development-team-facing thung). Can you compile zsh yourself from git master? |
Besides placing |
@StrangeRanger Per the last comment, the issue is already fixed in zsh-syntax-highlighting master against zsh master. If you use a released zsh, you can either wait for a zsh release or manually enable zsh-syntax-highlighting's redrawhook codepath. I can elaborate on the latter later if interested. |
@danielshahaf Is it supposed to be fixed to the point where it pastes instantly, or just that the speed is increased? Because it seems to be much faster but isn't instant compared to using the previous fix. |
@StrangeRanger Is that in |
@danielshahaf No, it's not in
|
@StrangeRanger That's a released zsh. The performance fix requires a newer zsh than that.
|
@danielshahaf So the problem wasn't entirely the fault of I just reread one of your comments "already fixed in zsh-syntax-highlighting master against zsh master". Didn't see you say "zsh master" part. Sorry about that. |
@StrangeRanger Yes, though s/problem/missing feature/ (the No worries. |
Fixed by proposal presented in the commment: zsh-users/zsh-syntax-highlighting#295 (comment) Closes #14
Fixed by proposal presented in the commment: zsh-users/zsh-syntax-highlighting#295 (comment) Closes #14
Delayed pasting was fixed for me in #835. How to update to the newest version of
|
Delayed pasting was fixed for me in
#835.
Thanks for the update.
#### How to update to the newest version of `zsh-syntax-highlighting`:
1. Go to the folder which you cloned `zsh-syntax-highlighting` into.
e.g. `~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting`
2. Run `git pull`
[to everyone] Note that the procedure will be different if you have installed zsh-syntax-highlighting differently. See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md for an overview of the installation options.
|
I have string copied from my text editor:
zle -U
to paste command from history (https://github.com/psprint/zsh-navigation-tools/blob/master/n-history#L46) it works very long (10m+) both on local and remote.Of course I do not use such extreme commands like in this example, but commands I use when I am pasting are long enough to make the lagging of 5-10 seconds.
The text was updated successfully, but these errors were encountered: