Hi,
here is another slight improvement to syntax/vim.vim

When analyzing vim/vim#2712 I found that the syntax definition 
vimNotation is notorious bad. I think this is, because it uses many OR 
branches, which the new engine is known not to handle good. Therefore, 
enable explicitly the old engine for parsing that kind of items.

That made an improvement from

TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
0.160759   4571   2149    0.001149    0.000035  vimNotation        
\(\\\|<lt>\)\=<\([scamd]-\)\{0,4}x\=\(f\d\{1,2}\|[^ 
\t:]\|cr\|lf\|linefeed\|return\|k\=del\%[ete]\|bs\|backspace\|tab\|esc\|right\|left\|help\|undo\|insert\|ins\|k\=home\|k\=end\|kplus\|kminus\|kdivide\|

TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
0.001967   3087   0       0.000092    0.000001  vimNotation        
\%#=1\(\\\|<lt>\)\=<\([scamd]-\)\{0,4}x\=\(f\d\{1,2}\|[^ 
\t:]\|cr\|lf\|linefeed\|return\|k\=del\%[ete]\|bs\|backspace\|tab\|esc\|right\|left\|help\|undo\|insert\|ins\|k\=home\|k\=end\|kplus\|kminus\|kdiv


diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index 48b02970e..cbc0662ce 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -416,7 +416,7 @@ syn match   vimMenuBang     "!"     contained skipwhite 
nextgroup=@vimMenuList
 " Angle-Bracket Notation (tnx to Michael Geddes) {{{2
 " ======================
 syn case ignore
-syn match      vimNotation     
"\(\\\|<lt>\)\=<\([scamd]-\)\{0,4}x\=\(f\d\{1,2}\|[^ 
\t:]\|cr\|lf\|linefeed\|return\|k\=del\%[ete]\|bs\|backspace\|tab\|esc\|right\|left\|help\|undo\|insert\|ins\|k\=home\|k\=end\|kplus\|kminus\|kdivide\|kmultiply\|kenter\|kpoint\|space\|k\=\(page\)\=\(\|down\|up\|k\d\>\)\)>"
 contains=vimBracket
+syn match      vimNotation     
"\%#=1\(\\\|<lt>\)\=<\([scamd]-\)\{0,4}x\=\(f\d\{1,2}\|[^ 
\t:]\|cr\|lf\|linefeed\|return\|k\=del\%[ete]\|bs\|backspace\|tab\|esc\|right\|left\|help\|undo\|insert\|ins\|k\=home\|k\=end\|kplus\|kminus\|kdivide\|kmultiply\|kenter\|kpoint\|space\|k\=\(page\)\=\(\|down\|up\|k\d\>\)\)>\%#=0"
 contains=vimBracket
 syn match      vimNotation     
"\(\\\|<lt>\)\=<\([scam2-4]-\)\{0,4}\(right\|left\|middle\)\(mouse\)\=\(drag\|release\)\=>"
     contains=vimBracket
 syn match      vimNotation     
"\(\\\|<lt>\)\=<\(bslash\|plug\|sid\|space\|bar\|nop\|nul\|lt\)>"               
contains=vimBracket
 syn match      vimNotation     '\(\\\|<lt>\)\=<C-R>[0-9a-z"%#:.\-=]'he=e-1     
                contains=vimBracket


Best,
Christian

On Do, 15 Mär 2018, Dominique Pellé wrote:

> Dear Charles
> 
> Please consider the following patch to the runtime/syntax/vim.vim
> syntax file.
> 
> It contains simple regexp optimizations  In particular, it speeds up
> the regexp of vimFunc which is the slowest according to
> ":syntime report".  The optimization only helps when using
> "set re=1". With "set re=0" the timing are the same before
> or after optimization.
> 
> My measurement shows the following timing before and after
> patch for the slowest regexp reported by vimFunc using "set re=1".
> 
> Before patch:
> 
>   TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
>   0.080835   2974   1352    0.000668    0.000027  vimFunc
> \%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%([a-zA-Z0-9_]\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*(
> 
> After patch:
> 
>  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
>   0.059000   2974   1352    0.000481    0.000020  vimFunc
> \%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*(
> 
> The patch replaces things like [0-9A-Za-z_] into \w which
> is faster with set re=1 as described in :help /\]
> 
> === BEGIN QUOTE  :help /\]
> - Matching with a collection can be slow, because each character in
>   the text has to be compared with each character in the collection.
>   Use one of the other atoms above when possible.  Example: "\d" is
>   much faster than "[0-9]" and matches the same characters.
> === END QUOTE
> 
> This was further discussed in this comment:
> 
> https://github.com/vim/vim/issues/2712#issuecomment-372780984
> 
> Regards
> Dominique
> 

> diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
> index 48b0297..65438a0 100644
> --- a/runtime/syntax/vim.vim
> +++ b/runtime/syntax/vim.vim
> @@ -164,7 +164,7 @@ endif
>  syn match vimNumber  "\<\d\+\%(\.\d\+\%([eE][+-]\=\d\+\)\=\)\=" skipwhite 
> nextgroup=vimGlobal,vimSubst,vimCommand
>  syn match vimNumber  "-\d\+\%(\.\d\+\%([eE][+-]\=\d\+\)\=\)\="  skipwhite 
> nextgroup=vimGlobal,vimSubst,vimCommand
>  syn match vimNumber  "\<0[xX]\x\+"
> -syn match vimNumber  "\%(^\|[^a-zA-Z]\)\zs#\x\{6}"
> +syn match vimNumber  "\%(^\|\A\)\zs#\x\{6}"
>  
>  " All vimCommands are contained by vimIsCommands. {{{2
>  syn match vimCmdSep  "[:|]\+"        skipwhite 
> nextgroup=vimAddress,vimAutoCmd,vimIsCommand,vimExtCmd,vimFilter,vimLet,vimMap,vimMark,vimSet,vimSyntax,vimUserCmd
> @@ -428,15 +428,15 @@ syn case match
>  " User Function Highlighting {{{2
>  " (following Gautam Iyer's suggestion)
>  " ==========================
> -syn match vimFunc            
> "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%([a-zA-Z0-9_]\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*("
>               contains=vimFuncName,vimUserFunc,vimExecute
> -syn match vimUserFunc contained      
> "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%([a-zA-Z0-9_]\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\<if\>"
>         contains=vimNotation
> +syn match vimFunc            
> "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*("
>                 contains=vimFuncName,vimUserFunc,vimExecute
> +syn match vimUserFunc contained      
> "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\<if\>"
>   contains=vimNotation
>  syn match vimNotFunc "\<if\>\|\<el\%[seif]\>\|\<return\>\|\<while\>"
>  
>  " Errors And Warnings: {{{2
>  " ====================
>  if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimfunctionerror")
>   syn match   vimFunctionError        "\s\zs[a-z0-9]\i\{-}\ze\s*("            
>         contained contains=vimFuncKey,vimFuncBlank
> -" syn match  vimFunctionError        
> "\s\zs\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)[0-9]\i\{-}\ze\s*("   contained 
> contains=vimFuncKey,vimFuncBlank
> +" syn match  vimFunctionError        
> "\s\zs\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\d\i\{-}\ze\s*("      contained 
> contains=vimFuncKey,vimFuncBlank
>   syn match   vimElseIfErr    "\<else\s\+if\>"
>   syn match   vimBufnrWarn    /\<bufnr\s*(\s*["']\.['"]\s*)/
>  endif
> @@ -553,7 +553,7 @@ syn match vimIsCommand    "<Bar>\s*\a\+"  transparent 
> contains=vimCommand,vimNotatio
>  " ============
>  syn cluster  vimHighlightCluster             
> contains=vimHiLink,vimHiClear,vimHiKeyList,vimComment
>  if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimhictermerror")
> - syn match   vimHiCtermError contained       "[^0-9]\i*"
> + syn match   vimHiCtermError contained       "\D\i*"
>  endif
>  syn match    vimHighlight    "\<hi\%[ghlight]\>"     skipwhite 
> nextgroup=vimHiBang,@vimHighlightCluster
>  syn match    vimHiBang       contained       "!"     skipwhite 
> nextgroup=@vimHighlightCluster


Mit freundlichen Grüßen
Christian
-- 
Gewohnheit bedeutet, einen bestimmten Platz für jede Sache zu haben,
und sie niemals dort aufzubewahren.
                -- Mark Twain (eigl. Samuel Langhorne Clemens)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui