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

Slowness when pasting commands with bracketed-paste-magic enabled; slowness with zle -U #295

Closed
doubleloop opened this issue Apr 22, 2016 · 41 comments

Comments

@doubleloop
Copy link

doubleloop commented Apr 22, 2016

I have string copied from my text editor:

echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  • when I paste it to my local machine (zsh 5.2) it will run for more then 10 minutes with 100% cpu usage
  • when I disable zsh-syntax-highlighting, it is pasted instantly
  • when I ssh to my remote machine (zsh 5.0.2), it is also pasted almost instantly with zsh-syntax-highlighting enabled.. (I have exactly the same configuration of zsh on my remote)
  • when I use ctrl+r wpapper (zsh-navigation-tools) wich uses 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.

@danielshahaf
Copy link
Member

I cannot reproduce that: when I paste your long echo aa…aa command, it is pasted instantly and rendered in reverse video. Using zsh 5.3-to-be from git master.

Can you reproduce it in zsh -f + source zsh-syntax-highlighting.zsh? Do you use a framework (oh-my-zsh/prezto/antigen/etc)? Do you use bracketed-paste-magic?

Workaround: set ZSH_HIGHLIGHT_MAXLENGTH=300 in your .zshrc.

@doubleloop
Copy link
Author

doubleloop commented Apr 22, 2016

Hmm, I can not reproduce it with zsh -f + source zsh-syntax-highlighting.zsh..
I am using oh-my-zsh. I will try to investigate more, still if you have any suggestions what to look for it would be helpful.

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:

@doubleloop
Copy link
Author

The workaround reduced time to about 7 seconds:)

@doubleloop
Copy link
Author

I investigated more and the line that was causing the problem is:

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)

if I comment it, the problem disappears.

@danielshahaf
Copy link
Member

I can reproduce this: with your highlighters setting, pasting your example text to zsh -f, and even typing a single space at the end of it, is noticeably slow (I'm seeing subsecond delays, but it's still noticeable).

@danielshahaf
Copy link
Member

zprof output is basically what you'd expect:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    6        1347.66   224.61   98.12%   1347.66   224.61   98.12%  _zsh_highlight_brackets_highlighter
 2)    7        1372.82   196.12   99.95%     20.52     2.93    1.49%  _zsh_highlight_call_widget
 3)    7        1352.30   193.19   98.46%      3.79     0.54    0.28%  _zsh_highlight
 4)    7           0.76     0.11    0.06%      0.39     0.06    0.03%  _zsh_highlight_brackets_highlighter_predicate
 5)    5           5.39     1.08    0.39%      0.37     0.07    0.03%  _zsh_highlight_widget_self-insert
 6)    7           0.32     0.05    0.02%      0.32     0.05    0.02%  _zsh_highlight_cursor_moved
 7)    1           1.07     1.07    0.08%      0.12     0.12    0.01%  _zsh_highlight_widget_accept-line
 8)    1        1366.96  1366.96   99.52%      0.10     0.10    0.01%  _zsh_highlight_widget_bracketed-paste
 9)    1           0.09     0.09    0.01%      0.09     0.09    0.01%  _zsh_highlight_apply_zle_highlight
10)    1           0.07     0.07    0.01%      0.07     0.07    0.01%  _zsh_highlight_preexec_hook
11)    1           0.05     0.05    0.00%      0.05     0.05    0.00%  _zsh_highlight_buffer_modified

@ericfreese
Copy link
Member

Pretty sure this has to do with bracketed-paste-magic. See zsh-users/zsh-autosuggestions#141

@danielshahaf
Copy link
Member

@ericfreese I can reproduce slowness in zsh -f with only ZSH_HIGHLIGHT_HIGHLIGHTERS=(brackets), i.e., without bracketed-paste-magic. I guess these are two separate issues, then: one in the brackets highlighter and one involving b-p-magic.

@danielshahaf
Copy link
Member

Breaking out the two for loops in _zsh_highlight_brackets_highlighter into subfunctions gives:

% zprof
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    6        1352.17   225.36   97.96%   1352.17   225.36   97.96%  f
 2)    7        1379.45   197.06   99.94%     19.26     2.75    1.40%  _zsh_highlight_call_widget
 3)    7        1360.19   194.31   98.54%      5.48     0.78    0.40%  _zsh_highlight
 4)    6        1353.63   225.61   98.07%      1.25     0.21    0.09%  _zsh_highlight_brackets_highlighter
 5)    5           9.30     1.86    0.67%      0.57     0.11    0.04%  _zsh_highlight_widget_self-insert
 6)    7           0.99     0.14    0.07%      0.49     0.07    0.04%  _zsh_highlight_brackets_highlighter_predicate
 7)    7           0.45     0.06    0.03%      0.45     0.06    0.03%  _zsh_highlight_cursor_moved
 8)    6           0.21     0.04    0.02%      0.21     0.04    0.02%  g
 9)    1           1.12     1.12    0.08%      0.13     0.13    0.01%  _zsh_highlight_widget_accept-line
10)    1        1369.83  1369.83   99.24%      0.10     0.10    0.01%  _zsh_highlight_widget_bracketed-paste
11)    1           0.09     0.09    0.01%      0.09     0.09    0.01%  _zsh_highlight_apply_zle_highlight
12)    1           0.07     0.07    0.01%      0.07     0.07    0.01%  _zsh_highlight_preexec_hook
13)    1           0.06     0.06    0.00%      0.06     0.06    0.00%  _zsh_highlight_buffer_modified

Here, f is the first for loop and g the second.

@danielshahaf
Copy link
Member

@doubleloop Is the behaviour under zsh -f with ZSH_HIGHLIGHT_HIGHLIGHTERS=(brackets) identical to the behaviour you were originally seeing?

danielshahaf added a commit that referenced this issue Apr 22, 2016
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.
@danielshahaf
Copy link
Member

@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

@doubleloop
Copy link
Author

doubleloop commented Apr 22, 2016

Strange.
I pulled current master with your commit (b52a485).

  1. In case of zsh -f and ZSH_HIGHLIGHT_HIGHLIGHTERS=(brackets) there is no problem (still there is tiny improvement when I compare before and after commit but we talk about less then second)
  2. When I use oh-my-zsh (current master) with all stuff commented out so entire zshrc file is this:
export ZSH=$HOME/.oh-my-zsh
plugins=(
    zsh-syntax-highlighting 
)
source $ZSH/oh-my-zsh.sh
ZSH_HIGHLIGHT_HIGHLIGHTERS=(brackets)

the issue is there (10+ minutes). When I comment ZSH_HIGHLIGHT_HIGHLIGHTERS=(brackets) everything works ok. In this situation the newest commit does not matter nor the patch you posted. I've never read oh-my-zsh code so just in case I did rm -rf ~/.oh-my-zsh/cache/* before testing.

@danielshahaf
Copy link
Member

danielshahaf commented Apr 23, 2016

Given that it works in zsh -f iff oh-my-zsh is not loaded, I'm going to have to suggest that you follow up with the oh-my-zsh project. (If the bug is in z-sy-h I'd love to fix it, but I'd like to be able to work with a minimal example, which source oh-my-zsh.sh isn't.)

You might look into zprof, or potentially just run set -x interactively and see what's being printed during the 10 minutes wait, to determine what's causing the slowness.

@ericfreese
Copy link
Member

ericfreese commented Apr 25, 2016

@doubleloop I'm almost positive your problem is from bracketed-paste-magic, which is enabled by Oh My Zsh in zsh versions 5.1 and up: https://github.com/robbyrussell/oh-my-zsh/blob/35517457921c095be1aa6ed948debfbe183b89ac/lib/misc.zsh#L7-L10

With bracketed-paste-magic enabled, every pasted character is re-processed as a self-insert (which is overriden by _zsh_highlight_bind_widgets), triggering the highlighter at least once for every character pasted.

@doubleloop
Copy link
Author

Yes, i used zstyle ':bracketed-paste-magic' active-widgets '.self-*' and it works like charm (instant pasting as expected). Thank you!

@danielshahaf
Copy link
Member

@ericfreese Thanks for following up To summarize, there are two unrelated issues here:

  1. oh-my-zsh enables bracketed-paste-magic: Slowness when pasting commands with bracketed-paste-magic enabled; slowness with zle -U #295 (comment)
  2. Far minorer slowness in the first for loop in _zsh_highlight_brackets_highlighter: Slowness when pasting commands with bracketed-paste-magic enabled; slowness with zle -U #295 (comment)

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.

@ericfreese
Copy link
Member

ericfreese commented Apr 27, 2016

The first one may deserve an upstream bug report or a FAQ addition here

I've been looking at ways to support bracketed-paste-magic out of the box in zsh-autosuggestions (zsh-users/zsh-autosuggestions#141), and I think it would boil down to disabling the plugin while bpm is doing its work. Is that something you would consider adding to zsh-syntax-highlighting? Where do you draw the line when it comes to supporting other zsh "plugins"? I'm still trying to figure out this balance with zsh-autosuggestions.

@danielshahaf
Copy link
Member

@ericfreese For z-sy-h I plan to ditch the "wrap all widgets" approach altogether, in favour of just using zle-line-pre-redraw, see #245. I think this mostly sidesteps the issue, assuming pasting with bracketed-paste-magic active only invokes the pre-redraw hook once, at the end.

Would this approach work for zsh-autosuggestions?

@danielshahaf
Copy link
Member

P.S. workers/37639 discussed a potential situation in which multiple plugins would want to hook to zle-line-pre-redraw.

@ericfreese
Copy link
Member

@danielshahaf

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?

workers/37639 discussed a potential situation in which multiple plugins would want to hook to zle-line-pre-redraw.

Was any code ever merged to address this? Seems pretty important to be able to have multiple plugins hook to it.

... to appear in zsh-5.3.

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+?

@danielshahaf
Copy link
Member

@ericfreese

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?

That's how it seems to behave: if widget f calls repeat 3 zle g, then invoking f invokes zle-line-pre-redraw just once. (Tested with zle-line-pre-redraw() { zle -M "$(( ++iii ))" }.)

Was any code ever merged to address this? Seems pretty important to be able to have multiple plugins hook to it.

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.

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+?

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 paste-init/paste-finish approach seems like a good solution; or perhaps we could look for bracketed-paste in $funcstack in the wrappers' entry points, although I guess we'd still have to register paste-finish hooks to do the actual work post-paste. (Re using $funcstack, so far I've tried to avoid relying on zsh/parameter being available, although I haven't heard of a build that doesn't include it.)

By the way, is there an accepted abbreviation for "zsh-autosuggestions" (like "z-sy-h" for "zsh-syntax-highlighting")?

@ericfreese
Copy link
Member

@danielshahaf $funcstack was exactly what I was looking for! You might be interested in my proposed solution for zsh-users/zsh-autosuggestions#141: See 7026544.

Bpm works by intercepting the paste action and calling self-insert for each character. The fix is to only fetch suggestions for the first invocation of the widget functions, and skip fetching suggestions for subsequent recursions.

By the way, is there an accepted abbreviation for "zsh-autosuggestions" (like "z-sy-h" for "zsh-syntax-highlighting")?

Nope! I've just gotten relatively practiced at typing it. Would be nice though. How about "z-asug"?

@danielshahaf
Copy link
Member

@ericfreese

Bpm works by intercepting the paste action and calling self-insert for each character. The fix is to only fetch suggestions for the first invocation of the widget functions, and skip fetching suggestions for subsequent recursions.

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.)

Nope! I've just gotten relatively practiced at typing it. Would be nice though. How about "z-asug"?

LGTM, it doesn't seem to be a word or an existing trademark.

@psprint
Copy link
Contributor

psprint commented May 14, 2016

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 git checkout 61f4325 (one commit before the 12b879c) it's 10 seconds. What's happening?

@danielshahaf
Copy link
Member

danielshahaf commented May 19, 2016

Pressing Ctrl-T causes 4 second delay. That's with recent fork optimization. With git checkout 61f4325 (one commit before the 12b879c) it's 10 seconds. What's happening?

You raised this on list and Bart speculated it was due to $PENDING not being set: workers/38494.

So, to summarise:

  • Pasting slowness is likely due to interaction with bracketed-paste-magic.
  • zle -U slowness is likely due to upstream not setting $PENDING.

This issue should probably be bifurcated.

@drewwells
Copy link

is there a fix available?

Eeemil added a commit to Eeemil/dotfiles that referenced this issue Mar 5, 2019
@jdelafon
Copy link

According to the commit reference above, there is a clue in some zstyle ':bracketed-paste-magic' active-widgets '.self-*' command in .zshrc .

@danielshahaf danielshahaf changed the title Pasting commands from clipboard are slow, same as using zle -U Slowness when pasting commands with bracketed-paste-magic enabled; slowness with zle -U Jul 14, 2020
danielshahaf added a commit that referenced this issue Jul 14, 2020
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.)
@danielshahaf
Copy link
Member

In my testing, the bracketed-paste-magic interaction is fixed on the feature/redrawhook branch. (I tested in zsh -f with just bracketed-paste-magic enabled. If you still see slowness, post reproduction instructions in zsh -f using no external dependencies.)

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 brackets optimization in cdd7f89.

As to the zle -U issue, anyone interested in it please create a new ticket for it. Thanks.

@aaronjensen
Copy link

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?

@danielshahaf
Copy link
Member

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?

@StrangeRanger
Copy link

StrangeRanger commented Mar 18, 2021

Besides placing zstyle ':bracketed-paste-magic' active-widgets '.self-*' in my .zshrc, does this issue not have an official built-in fix? From what I can tell, the issue SHOULD be fixed, but it's still slow for me.

@danielshahaf
Copy link
Member

@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.

@StrangeRanger
Copy link

@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.

@danielshahaf
Copy link
Member

@StrangeRanger Is that in zsh -f with no other plugins? What's $ZSH_PATCHLEVEL and the pasted text?

@StrangeRanger
Copy link

StrangeRanger commented Mar 20, 2021

@danielshahaf No, it's not in zsh -f. Is that necessary? What exactly does zsh -f do?

❯ echo $ZSH_PATCHLEVEL
zsh-5.8-0-g77d203f

@danielshahaf
Copy link
Member

@StrangeRanger That's a released zsh. The performance fix requires a newer zsh than that.

-f bypasses most dotfiles; see zshoptions(1).

@StrangeRanger
Copy link

StrangeRanger commented Mar 21, 2021

@danielshahaf So the problem wasn't entirely the fault of zsh-syntax-highlighting? It was partially a problem with my current and the previous versions of zsh itself?

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.

@danielshahaf
Copy link
Member

@StrangeRanger Yes, though s/problem/missing feature/ (the memo support in region_highlight).

No worries.

RiddleMan added a commit to RiddleMan/dotfiles that referenced this issue Nov 16, 2021
RiddleMan added a commit to RiddleMan/dotfiles that referenced this issue Nov 16, 2021
@DrJume
Copy link

DrJume commented Dec 6, 2021

Delayed pasting was fixed for me in #835.

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

@danielshahaf
Copy link
Member

danielshahaf commented Dec 7, 2021 via email

matthinea added a commit to matthinea/dotfiles that referenced this issue Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants