You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Being slow with large inputs is a known issue. There seems to be two main causes:
Iteration over a string is quadratic.
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.
I didn't really find a func named _zsh_highlight_main_highlighter_highlight_argument, but I think you mean add return 0 in front of line 652 in main-highlighter.zsh
It did work a little faster
Tip in #86 is a good idea, I think I will just disable highlighting when I have a very large input
Ah forgot the current release doesn't have that function. Where you added it will do similar, but may mess up the state in some cases. Don't think there's a single line change that'd work in the current release.
There's also the possibility to replace some loops with an while i=$arg[(ib:... style loop as in https://github.com/phy1729/zsh-syntax-highlighting/tree/ib-subscript . Haven't had much chance to test it, but I think it improved some cases and worsened others. It would be helpful to have a performance test suite to more rigorously test each change.
The issue with make perf is that it reuses the test suite data which is probably not reflective of a user's typical buffer. The performance for single quoted, double quoted, and non-quoted strings are all different. Depending on what mix is typical code changes may be performance gains or losses. E.g. changing the bracket highlighter's loop to while pos=$BUFFER[(ib:pos+1:)[\{\}\(\)\[\]]]; (( pos <= buflen )); do
was faster if every third character or fewer was a bracket but slower if every character is a bracket (an unlikely case). For the main highlighter the change made it slower to highlight the master version of main-highlighter.zsh. I don't know if that result has any bearing on a typical user's experience.
Array appends are quadratic are discussed in #388. We could open an issue for string iteration being quadratic.
I encounter the similar issue when I copy curl command with long headers. I wonder if it is possible to disable the zsh-syntac-highlighting for specific prefix (like curl)?
I'd recommend just using ZSH_HIGHLIGHT_MAXLENGTH as @ludanxer suggested. Alternatively, you could patch that part of z-sy-h's source to do something like if [[ $PREBUFFER == *curl* || $BUFFER == *curl* ]]; then return; fi.
Activity
phy1729 commentedon Apr 5, 2018
(Related to #240.)
Being slow with large inputs is a known issue. There seems to be two main causes:
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 disableand 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.haoranpb commentedon Apr 6, 2018
Thx a lot!
I didn't really find a func named
_zsh_highlight_main_highlighter_highlight_argument
, but I think you mean addreturn 0
in front of line 652 in main-highlighter.zshIt did work a little faster
Tip in #86 is a good idea, I think I will just disable highlighting when I have a very large input
phy1729 commentedon Apr 6, 2018
Ah forgot the current release doesn't have that function. Where you added it will do similar, but may mess up the state in some cases. Don't think there's a single line change that'd work in the current release.
There's also the possibility to replace some loops with an
while i=$arg[(ib:...
style loop as in https://github.com/phy1729/zsh-syntax-highlighting/tree/ib-subscript . Haven't had much chance to test it, but I think it improved some cases and worsened others. It would be helpful to have a performance test suite to more rigorously test each change.haoranpb commentedon Apr 6, 2018
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!!
danielshahaf commentedon Apr 6, 2018
@phy1729 Do you recall that
make perf
exists? I realise it has room for improvement.Shall we open separate tickets for the two "X is quadratic" issues you identify?
phy1729 commentedon Apr 6, 2018
The issue with
make perf
is that it reuses the test suite data which is probably not reflective of a user's typical buffer. The performance for single quoted, double quoted, and non-quoted strings are all different. Depending on what mix is typical code changes may be performance gains or losses. E.g. changing the bracket highlighter's loop towhile pos=$BUFFER[(ib:pos+1:)[\{\}\(\)\[\]]]; (( pos <= buflen )); do
was faster if every third character or fewer was a bracket but slower if every character is a bracket (an unlikely case). For the main highlighter the change made it slower to highlight the master version of main-highlighter.zsh. I don't know if that result has any bearing on a typical user's experience.
Array appends are quadratic are discussed in #388. We could open an issue for string iteration being quadratic.
Yriuns commentedon Dec 8, 2018
I encounter the similar issue when I copy
curl
command with long headers. I wonder if it is possible to disable thezsh-syntac-highlighting
for specific prefix (likecurl
)?danielshahaf commentedon Dec 8, 2018
I'd recommend just using
ZSH_HIGHLIGHT_MAXLENGTH
as @ludanxer suggested. Alternatively, you could patch that part of z-sy-h's source to do something likeif [[ $PREBUFFER == *curl* || $BUFFER == *curl* ]]; then return; fi
.Yriuns commentedon Dec 8, 2018
Thanks I lot. I think I will use the former one.
flakrat commentedon Jun 13, 2019
Thanks for sharing the
ZSH_HIGHLIGHT_MAXLENGTH
variable. Pasting blocks of script to the terminal was so slow I was about to disable the plugin.Fixed slow paste issue with zsh-syntax-highlighting plugin
19 remaining items