Skip to main content
rewrote test case, hoepfully more reproduceable
Source Link
artfulrobot
  • 611
  • 1
  • 5
  • 14

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:Test case

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

A test case: No plugins; and only this, which must be the most minimal foldexpr function possible (and is completely useless, except for counting invocations) in .vimrc:

let g:c = 0 
function! Myfoldexpr() 
   let g:c = 1 + g:c 
   return '=''0' 
endfunction 

Then make a fileNow start vim with 10a blank document. We'll copy the first 100 lines of Vim's own help file, and then run autocomplete line, choosing the 10th suggestion, then see how many times foldexpr was called.

:set fdm=expr help
y100j:q
P:set foldexpr=Myfoldexpr() 
:echo g:cset fdm=expr

It will say 11.

zx O<C-X><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><Esc>
:echo g:c 
2088

it will say 22

Now editthat's a new100 line file, with relatively short lines and pressthe foldexpr was called 2088 times (although 100 of these are done when first setting the foldexpr). Efficient foldexpr is obviously good, but we programmers ask a lot of our foldexpr, so they are necessarily non-trivial, and when their execution time is multiplied by several thousand it makes you choose between autocomplete or indent for productivity. Being greedy/lazy I'd like to be able to use both! Beyond attempting to rewrite several pretty well established foldexpr-based folding plugins (I've tried rewriting php-folding and after days of trying to optimise it to a workable state I gave up on foldexpr for php), perhaps there's a way to use a mapping to turn <C-X>Lfdm=manual before autocomplete or some such?

:echo g:c 
it now says 33 or 34 

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

A test case:

let g:c = 0 
function! Myfoldexpr() 
   let g:c = 1 + g:c 
   return '=' 
endfunction 

Then make a file with 10 lines.

:set fdm=expr 
:set foldexpr=Myfoldexpr() 
:echo g:c 

It will say 11.

zx 
:echo g:c 

it will say 22

Now edit a new line and press <C-X>L

:echo g:c 
it now says 33 or 34 

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: Test case

A test case: No plugins; and only this, which must be the most minimal foldexpr function possible (and is completely useless, except for counting invocations) in .vimrc:

let g:c = 0 
function! Myfoldexpr() 
   let g:c = 1 + g:c 
   return '0' 
endfunction

Now start vim with a blank document. We'll copy the first 100 lines of Vim's own help file, and then run autocomplete line, choosing the 10th suggestion, then see how many times foldexpr was called.

:help
y100j:q
P:set foldexpr=Myfoldexpr()
:set fdm=expr
O<C-X><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><C-L><Esc>
:echo g:c
2088

Now that's a 100 line file, with relatively short lines and the foldexpr was called 2088 times (although 100 of these are done when first setting the foldexpr). Efficient foldexpr is obviously good, but we programmers ask a lot of our foldexpr, so they are necessarily non-trivial, and when their execution time is multiplied by several thousand it makes you choose between autocomplete or indent for productivity. Being greedy/lazy I'd like to be able to use both! Beyond attempting to rewrite several pretty well established foldexpr-based folding plugins (I've tried rewriting php-folding and after days of trying to optimise it to a workable state I gave up on foldexpr for php), perhaps there's a way to use a mapping to turn fdm=manual before autocomplete or some such?

Copy the test case from the mail post. This is useful info :-)
Source Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

A test case:

let g:c = 0 
function! Myfoldexpr() 
   let g:c = 1 + g:c 
   return '=' 
endfunction 

Then make a file with 10 lines.

:set fdm=expr 
:set foldexpr=Myfoldexpr() 
:echo g:c 

It will say 11.

zx 
:echo g:c 

it will say 22

Now edit a new line and press <C-X>L

:echo g:c 
it now says 33 or 34 

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

A test case:

let g:c = 0 
function! Myfoldexpr() 
   let g:c = 1 + g:c 
   return '=' 
endfunction 

Then make a file with 10 lines.

:set fdm=expr 
:set foldexpr=Myfoldexpr() 
:echo g:c 

It will say 11.

zx 
:echo g:c 

it will say 22

Now edit a new line and press <C-X>L

:echo g:c 
it now says 33 or 34 
added 263 characters in body
Source Link
artfulrobot
  • 611
  • 1
  • 5
  • 14

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs.

I can't see the value in having foldexpr consulted while running through auto completes, so would like to disable this somehow so I get usable autocomplete back.

Any suggestions?


EDIT: some tests show:

  • Make a file with one character per 100 lines, do a <C-X>L - the foldexrp is evaluated about 150 times.

  • Make a file with ten characters per 100 lines, do the same - the foldexpr is evaluated about 7,500 times!

Source Link
artfulrobot
  • 611
  • 1
  • 5
  • 14
Loading