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

Including a simple table in the markdown drops performance drastically #34

Open oblitum opened 9 years ago

oblitum commented 9 years ago

In my machine I'm barely able to type when markdown includes a markdown table.

gabrielelana commented 9 years ago

@oblitum In what version of vim?

oblitum commented 9 years ago
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar  2 2015 18:50:09)
Included patches: 1-648
oblitum commented 9 years ago

I have to say that it's also being quite slow when there're fenced style code blocks in the file. These kinds of performance problems generally come from non-optimized regular expressions.

gabrielelana commented 8 years ago

@oblitum unfortunately I'm unable to reproduce the problem with vim 7.4 could you please provide me an example file?

oblitum commented 8 years ago

@gabrielelana IIRC this simple file (https://raw.githubusercontent.com/ccppbrasil/ccppbrasil.github.io/master/encontros.md) was barely navigable at the time. Sorry I've stopped using this plugin b/c of this a long time ago. Will have to install it again to try this. But at the time it was pretty easy for it to be quite slow just by having some tables.

liuyang1 commented 8 years ago

Also find this issue. this plugin is slow even only navigate markdown file. Hope to improve this point.

mcjohnalds commented 7 years ago

I've noticed very poor performance when the cursor is near a table, admittedly I'm on a weak processor. If I :syntax off then then the lag disappears, but obviously that isn't a great workaround.

janlazo commented 7 years ago

Clearning syntax groups can improve performance. I'm using the following code in vim 8 to remove link syntax.

syntax clear markdownUrlLinkInText
syntax clear markdownLinkUrl

Alternative is to use another plugin or switch to neovim.

dylan-chong commented 4 years ago

problem is still here.

here is an example of a table (scroll down so the table is not on screen, then c-u up to see the table and notice the 1s delay)


| AAAAAAA | AAAA AAA | AAAAA |
|-----------------------------------------------------|--------------------------------------------------------|------------------------------------------------------------------|
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA/AAAAAA.AAAA) | AAAA AA AAA AAAA AAAAAAA AAAA AAA AAA AAAAA AAAAA, AAAAAAAAAAA, AA & AAAAAA, AAAAAAAAA AAA AAAAAAAAA. |  |
| [AAA](AAAAA://AAAAAAA.AA/AAA/AAA.AAAA) | AAA AA A AAAAA AAAA AAAA AAAAAAAA AAAAA AAA AAAAAAAA, AAAAAAAAA, AAA AAAAAAA AAAAAA AAAAAAAA, AAAAAAAA AAA AAAAAAAAAAAA, AAA AAAA. | AAA AAA AAAA AAA AAAAAAA AAAA AA AAA AAA AAAAAAA AAAAAA AAA AAAAAAA AAAAA AAAAAAAAAA, AAAA AA AAAAAAAA AAA AAAAAAAAAAA. |
| [AAAA](AAAAA://AAAAAAA.AA/AAAA) | AAAA AAAAA AAAAAAAAAAAAA AAAAAAAAA AAAAAAA, AAAAAAA AAA AAAAAAAAAA. | AAAA AAA AAAA AAAAAA AAA AAAAAAAA. AAAA [AAAAAAAA]( AAAAA://AAA.AA/AAAAAAAA/AAAAAAAA) AAA [AAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAA) (AAAAAAAA AAAAAA). |
| [AAAA](AAAAA://AAA.AA/AAAAAAAA/AAAA) | AAAAAAAAA AAAAAA AAAAAA AAA AAAAAAAAA (AAAAAA). |  |
| [AAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAA/AAAAAAAA.AAAA) | AAA AAAAAAAAAAA AAAAAAAAA AAAAAAA AA AAAAAA AAAAA AAAAAAAAAA AAA AAAAAA-AAAA AAAAA AAAA AAAAAAAAAA (AAA) AAAAAAA. | AAAAAAAA AAA AAA AAAAAAAAA AAAA AA AAAAAAA AAA AAAAAAAA. AAAAAAAA AAAAAAAAAAA AAA AA AAAAAAAAAAAAAA AAAAAAAAA AA AAAA. |
| [AAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAA) | AAA AAAAAAA AAAAAAA AAA AAAAAA AAAAA AAAAAAAA AA AAAAAAAAAAAAAA AA AAA AAAAAAA AAAAAAAAAAAAA. |  |
| [AAAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAAA) | AAAA-AAAAAAAA AA AAAAAAAAA AAA/AA AAAAAAAAA. |  |
| [AAAAA](AAAAA://AAAAAAA.AA/AAAAA) | AAAA AAAA AAAAAA AAA AAAAAAAAA. |  |
| [AAAAA](AAAAA://AAAAAAA.AA/AAAAA) | AA AAAAAAAAAAA, AAAAAA AAAAAAAA, AAAAAA AAAAAAA AAAAAA AAAA: AAA AAAAAA AAAAA AAAAAA. :AAAAAA:. | AAAA AAA AAAAAAAAAAA AAAA AAAAA. |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA/AAAAA.AAAA) | A AAAAAAAA AAAA AA AAA AAA AA AAA AAAA. | AAA AAAAAAAAAAA AAAA AAA AAAAAA. |
| [AAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAA) | AAAA AAAAAA AAAAAAA (AAAAAA). |  |
| [AAAA](AAAAA://AAAAAAA.AA/AAAA) | AAA AAAAAAAAAA AAAAAAA AAAAAAA AAA AAAAAAAAAAAA. |  |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA) | AAAAAAAAA AAA AA-AAAAAA AAA/AAAAA AAAAAAA. |  |
| [AAAAAAAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAAAAAAA) | AAAAAAAAA AAA AAAAAAAAAA AAAAAAAAAA.AA AAAAAAAAAA AAAAAA AAA AAAA AAAAAA AAAAAAAA AAAAAA AA AAAAAA. |  |
| [AAAAAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAAAAA) | AAAAAAA AAAAAAAAA AA AAA AAAAAAA AAAAAAAAA. | AAAAAAAA AAAAAAAAA. |
| [AAAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAAA) | AAAA AAAAAAA. |  |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA) | AAAAAAA, AAAAAAA AAA AAAAAA. |  |
| [AAAAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAAAA) | AAAAAAAA AAA AAAAAAAAAA AAA AAAAAAA AA AAAAAA AAAA AAAAAAAAAA. |  |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA) | AAAAAAAA AAAAAAAA AAAAAAAAA AA AAAA AAAAAA AAAAAAAA. |  |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAAA/AAAAAA.AAAA) | AAAA AAAAAAA AAAAAAAAA AAA AAAAAA. | AAA AAAA AAAAA AA AAA AAAAA AAAAAA AAAA AAA AAAAAAAAAAA AAAAAAAAAAA AAAAA, AA AAAA AAAAA AAAAAAA AAAAAAA, AAAAA, AAAAAA AAA AAAAAAAA AAAAAAAAAAAA AA AAA. AAA AAAA AAAAAA, AAAA AAAAA AAA AAA AAAAAA AA AAAA AA A AAAAA AA AA A AAAA AAAAAAA AAAAAAAAA. |
| [AAA](AAAAA://AAAAAAA.AA/AAA/AAA.AAAA) | AAAAAA'A AAAAAAAAAAA AAAAA. | AAAAAAAAAAA AAAAAAAAA AAAAAAAA AAAA AAAAAAA AAAAA AAA AAAAAAAAAAA AAAAA. |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA/AAAAAA.AAAA) | A AAAAAA AAA AAAAAA AAAAAAAAAAAA. | AAA AAAAAAA AA AAAA AAAAAAA AAAAAA AAAA AAAA AAAAA-AAAAAAAA AAAAAAAAA. |
| [AAAAA](AAAAA://AAAAAAA.AA/AAAAA) | AAAAAAAA AAAA AAAAAAAAA AAAA, AAAAA AAAAAA AA AAAA AAAAA. |  |
| [AAAAAA](AAAAA://AAAAAAA.AA/AAAAAA) | AAAAAA AAAAAA. |  |
| [AAAAAAA](AAAAA://AAAAAAA.AA/AAAAAAA) | A AAAAAAA-AAAAA AAA AAA AAAAAAA AAAA AAAAAAAAAAAAAAAAA AAAAAAAAAAAA. |  |

A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A

A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A

i am using neovim

nvim --version NVIM v0.4.3 Build type: Release LuaJIT 2.0.5

rbuchberger commented 4 years ago

Sorry to pile on, but I'm having this issue as well, with neovim. janlazo's suggested fix had no impact. The worst effect is when moving up and down in normal mode.

❯ nvim --version
NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.3/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

That's not to say I'm not appreciative; this plugin is wonderful! Thanks so much for the time you've put into it.

antenore commented 4 years ago

The problem is in the syntax/markdown.vim but it's quite hard to find the root cause, probably some of the regewxp

Doing some profiling, like:

:profile start profile.log
:profile func *
:profile file *

{SLOW ACTIONS}

:profile pause

It shows, at least in my case, that there's nothing so slow to worry about.

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
   50   0.045313   0.001873  airline#extensions#branch#get_head()
   50   0.041770   0.001423  airline#extensions#branch#head()
   50   0.035763   0.002980  <SNR>138_update_branch()
   50   0.032551   0.001737  airline#extensions#tagbar#currenttag()
   21   0.030814   0.001590  tagbar#currenttag()
   23   0.029404   0.027110  <SNR>193_GetNearbyTag()
   50   0.028926   0.002682  <SNR>138_update_git_branch()
   50   0.024449   0.000803  FugitiveHead()
   50   0.022418   0.003442  fugitive#Head()
  100   0.019428   0.007310  airline#extensions#ale#get()
   50   0.018976   0.012381  fugitive#Find()
    2   0.012991   0.000473  DevhelpUpdate()
   50   0.012510   0.000304  airline#extensions#ale#get_warning()
   50   0.009450   0.008952  WebDevIconsGetFileTypeSymbol()
   50   0.008322   0.006811  airline#extensions#whitespace#check()
   50   0.007858             airline#check_mode()
   50   0.007549   0.000327  airline#extensions#ale#get_error()
  100   0.005769   0.001203  <SNR>140_airline_ale_get_line_number()
   12   0.005642   0.000719  ale#cursor#EchoCursorWarning()
  100   0.004635   0.000896  ale#statusline#Count()

So, as suggested I've first disabled the syntax

:set syntax=off

The problem is disappeared, but it's not what we want, right?

The second test was to use a (not so) random markdown.vim I've found around, again problem disappeared.

Afterwards I've used the VIM builtin syntax profiler (:help syntime) and the report will show you the guilty matching rules

  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
  2.492540   1984   1184    0.024817    0.001256  markdownTableHeader \%(|\?\s*\)\@<=[^|]\+\%(.*\n\%(\s*|\?\%(\s*[-:]-\{1,}[-:]\s*|\)\+\s*[-:]-\{1,}[-:]\s*|\?\s*\|\s*|\s*[-:]-\{1,}[-:]\s*|\s*\|\s*|\s*[-:]-\{1,}[-:]\s*\|\s*[-:]-\{1,}[-:]

  0.295872   800    96      0.005342    0.000370  markdownTableDelimiter \%(\s*|\?\%(\s*[-:]-\{1,}[-:]\s*|\)\+\s*[-:]-\{1,}[-:]\s*|\?\s*\|\s*|\s*[-:]-\{1,}[-:]\s*|\s*\|\s*|\s*[-:]-\{1,}[-:]\s*\|\s*[-:]-\{1,}[-:]\s*|\s*\)

The other plugin doesn't even highlight tables and headers

Uncommenting the code workaround the issue:

$ git diff
diff --git a/syntax/markdown.vim b/syntax/markdown.vim
index 85e9d53..5125718 100644
--- a/syntax/markdown.vim
+++ b/syntax/markdown.vim
@@ -349,10 +349,10 @@ execute 'syn match markdownTable '
   \ .   '$'
   \ . '/'
 syn match markdownTableDelimiter /|/ contained
-execute 'syn match markdownTableDelimiter contained '
-  \ . '/' . s:markdown_table_header_rows_separator . '/'
-execute 'syn match markdownTableHeader contained contains=@markdownInline '
-  \ . '/\%(|\?\s*\)\@<=[^|]\+\%(.*\n' . s:markdown_table_header_rows_separator . '\)\@=/'
+"execute 'syn match markdownTableDelimiter contained '
+  "\ . '/' . s:markdown_table_header_rows_separator . '/'
+"execute 'syn match markdownTableHeader contained contains=@markdownInline '
+  "\ . '/\%(|\?\s*\)\@<=[^|]\+\%(.*\n' . s:markdown_table_header_rows_separator . '\)\@=/'

 " }}}

I don't know how to fix it though :-p but I hope it may help someone

brycelelbach commented 3 years ago

I can confirm @antenore's workaround helps.