Subject: Re: Slow highlighting (Re: "drop-in replacement" and transpose-words-match)
From: Sebastian Gniazdowski <[email-masked]>
To: Bart Schaefer <[email-masked]>
Cc: Zsh hackers list <[email-masked]>
Date: Wed, 10 Feb 2016 17:32:48 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On 24 January 2016 at 07:20, Bart Schaefer <[email-masked]> wrote:
> On Jan 23, 11:53pm, Daniel Shahaf wrote:
> }
> } [Re-analyzing on every keystroke] doesn't explain the slowness on
> } fned buffers: the initial highlight of an fned buffer involves exactly
> } one _zsh_highlight call, and yet is slow.
>
> Is it similarly slow on any use of "vared"?  What about with a history
> line containing a function definition?

Isn't it that zsyh does a fork for each token it analyzes?

# NOTE: This runs 'setopt', but that should be safe since it'll only ever be
# called inside a $(...) subshell, so the effects will be local.
_zsh_highlight_main__type() {
  if (( $#options_to_set )); then
    setopt $options_to_set;
  fi
  LC_ALL=C builtin type -w -- $1 2>/dev/null
}

...
      local res="$(_zsh_highlight_main__type ${expanded_arg})"
...
      case $res in
        *': reserved')  style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
        *': suffix alias')
                        style=$ZSH_HIGHLIGHT_STYLES[suffix-alias]
                        ;;
        *': alias')     () {
...

Best regards,
Sebastian Gniazdowski