gabrielelana / vim-markdown

Markdown for Vim: a complete environment to create Markdown files with a syntax highlight that doesn't suck!
MIT License
740 stars 59 forks source link

Very slow on uncommon/invalid indentation #63

Closed cdoepmann closed 4 years ago

cdoepmann commented 7 years ago

Hi, I am experiencing vim-markdown to be extremely slow when processing a file like this:

      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
      - foo
- bar

The performance further degrades when more foo lines are added.

I am aware of the fact that this probably isn't valid or well-formed Markdown. However, I noticed it by accidentally indenting a bunch of lines, which resulted in vim effectively freezing. I do not think that this should happen even for arbitrary input.

I'm using:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 07 2017 03:33:23)
gavinchou commented 5 years ago

it's true, this is a problem, it is probably caused by the list item matching patterns, i am not sure. but i suggest you use tabs instead of spaces for indents, that may be a good practice and workaround though.

gavinchou commented 5 years ago

i've figured out what's the problem, with :syntime on and :syntime report

image

  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
 22.513534   14100  0       1.703281    0.001597  markdownCodeBlock  \%(^\n\)\@<=\%(\%(\s\{4,}\|\t\+\).*\n\)\+$

this regex takes too long to finish, to fix it, replace

syn match markdownCodeBlock /\%(^\n\)\@<=\%(\%(\s\{4,}\|\t\+\).*\n\)\+$/ contains=@NoSpell

in syntax/markdown.vim with

syn match markdownCodeBlock /\%(^\n\)\@<=\%(\%( \{4}\|\t\+\).*\n\)\+$/ contains=@NoSpell

it will fix the problem,

but it still takes several milliseconds, to me, i personal don't use spaces for indention, the following will be much faster

syn match markdownCodeBlock /\%(^\n\)\@<=\%(\%(\t\+\).*\n\)\+$/ contains=@NoSpell

and, this markdown syntax highlight has a lot of regexes that may consume a lot, i simplify some mathing rules to save rendering time, if any one encounters the performance issue of syntax highlight, give it a try to simplify the matching rules.

kwiliarty commented 5 years ago

This solution is working very well for me. Is there is chance it will get integrated?

gavinchou commented 5 years ago

hi! Wiliarty, i opened a pull request 5 months ago for this change, but it seems no one accepts the PR

here is my repo for vim, it contains all the changes which may affect performance

<github.com/gavinchou/vim_config>

check it (.vim/syntax/markdown.vim) out if you are interested in vim and dont forget to star it if it helps, LOL

kwiliarty commented 5 years ago

Looks nice. Thanks very much for the tip.

sheerun commented 4 years ago

@gavinchou Maybe you could create fork that fixes performance issues and add syntax highlight for code blocks?

gabrielelana commented 4 years ago

Fixed by #78