zsh-syntax-highlighting: Works so slow when I try to paste long string to terminal

I am just using main highlighter. At first, I thought if I just disable some styles, it will work fine. So I disabled all quoted-argument.

When I paste magnet:?xt=..t.nz after " into the terminal:

aria2c "magnet:?xt=urn:btih:90...er.fastcast.nz"

The highlight is gone, but it’s still really slow! I really love the highlighting, how can I make it faster?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

this gist works fine.

I viewed #86 and some of the source code again, came up with a temporary solution:

Add export ZSH_HIGHLIGHT_MAXLENGTH=60 in file .zshrc

Now it will just stop parse or highlight any long string, and this works well for me.

Thanks for your help!!

In my experience, if you paste something into the terminal and it’s taking a long time to draw, you can push any button on the keyboard (e.g. right arrow) and it’ll give up highlighting and draw the text.

(Related to #240.)

Being slow with large inputs is a known issue. There seems to be two main causes:

  1. Iteration over a string is quadratic.
  2. Array appends are quadratic.

I’ve briefly looked at solving the first in zsh, but I haven’t had time to make a complete patch.

With regards to disabling styles, setting a style to none doesn’t disable the code that parses for that style. We could add a flag to disable _zsh_highlight_main_highlighter_highlight_argument, but that would disable

  • single-hyphen-option
  • double-hyphen-option
  • history-expansion (sometimes)
  • globbing
  • path (and related styles)
  • single-quoted-argument (and -unclosed)
  • rc-quote
  • double-quoted-argument (and -unclosed)
  • dollar-double-quoted-argument
  • back-double-quoted-argument
  • dollar-quoted-argument (and -unclosed)
  • back-dollar-quoted-argument
  • back-quoted-argument (and -unclosed)

and once #512 is merged the highlighting of command and process substitution and their contents.

If that’s acceptable, you can add return 0 as the first command in _zsh_highlight_main_highlighter_highlight_argument. We could add a flag to do the same, but I think long term it’d be preferable to fix the quadratic issues in zsh.

This comment fixed it for me: https://github.com/zsh-users/zsh-syntax-highlighting/issues/295#issuecomment-214581607 and the issue is probably a duplicate of this one

forresthopkinsa that worked thanks