othree / html5.vim

HTML5 omnicomplete and syntax
http://www.vim.org/scripts/script.php?script_id=3236
934 stars 76 forks source link

Vendor Extension Attributes syntax match is too slow #83

Closed platosha closed 7 years ago

platosha commented 7 years ago
" Vendor Extension Attributes
" http://w3c.github.io/html/single-page.html#conformance-requirements-extensibility
syn match   htmlArg "\<\(x\-\([a-z_][a-z0-9_.\-]*\)\+\)\{2,}\>" contained

Having custom elements named like <x-my-custom-element></x-my-custom-element> makes editor unusably slow.

othree commented 7 years ago

I don't see any performance issue on my machine. And this line is for attribute, I don't think it will effect when your code only have html tag. Did you try remove this line, then reopen Vim to see the performance change?

platosha commented 7 years ago

@othree I tried commenting the line, and this resolved the performance issue.

Slow file example: https://github.com/vaadin/vaadin-grid/blob/091c567a26bb7ebcf708f3475cc048edd9fb4294/demo/data.html

Steps to reproduce:

  1. :e demo/data.html
  2. :syntime on
  3. Move around and scroll a few lines.
  4. :syntime report
  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
 38.189497   162    0       3.883480    0.235738  htmlArg            \<\(x\-\([a-z_][a-z0-9_.\-]*\)\+\)\{2,}\>
  0.001624   267    20      0.000032    0.000006  htmlTagName        \<\(b\|i\|u\|h[1-6]\|em\|strong\|head\|body\|title
  0.001348   374    124     0.000014    0.000004  htmlTagError       [^>]<
  0.001287   168    91      0.000037    0.000008  jsFuncCall         \k\+\%(\s*(\)\@=
  0.001188   98     0       0.000040    0.000012  jsArrowFuncArgs    \k\+\s*\%(=>\)\@=
  0.001152   257    132     0.000021    0.000004  htmlTagName
...
othree commented 7 years ago

Could you try the new patterns:

" Custom Data Attributes
" http://w3c.github.io/html/single-page.html#embedding-custom-non-visible-data-with-the-data-attributes
syn match   htmlArg "\<data[-.0-9_a-z]*-[-.0-9_a-z]*\>" contained

" Vendor Extension Attributes
" http://w3c.github.io/html/single-page.html#conformance-requirements-extensibility
syn match   htmlArg "\<x[-.0-9_a-z]*-[-.0-9_a-z]*\>" contained

I tested and have huge improve.

platosha commented 7 years ago

It’s much better now! Thanks a lot for fixing this quickly.