Hi,
I tried to create a custom fold expression for a file type. The
folding works as desired, but it makes vim terribly slow. Commands
like "gwip" to format the current paragraph take more than ten
seconds on a modern machine. Thanks to Drew [1] I heard about the
possibility to profile my expression and was surprised that it was
called millions of times for a file containing just a few dozen
lines.
I created a simple test expression and it is also called way more
often than I would expect. Here my test case:
" file: test
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
" endfile
" file: myfold.vim
function! MyFolds()
let thisline = getline(v:lnum)
if match(thisline, 'start') >= 0
return "a1"
elseif match(thisline, 'stop') >= 0
return "s1"
else
return "="
endfunction
setlocal foldmethod=expr
setlocal foldexpr=MyFolds()
function! TextManip()
normal gwip
endfunction
call TextManip()
" endfile
This is how I did the profiling:
vim --cmd 'profile start profile.result' \
--cmd 'profile! file myfold.vim' \
-c 'source myfold.vim' \
-c 'profdel file myfold.vim' \
test
The resulting file profile.result shows that the function MyFolds()
was called 52 times:
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
1 0.000961 0.000252 TextManip()
52 0.000709 MyFolds()
The test file contains just four lines. Why is it called 52 times?
And what can I do about that?
Marco
[1] http://vimcasts.org/episodes/profiling-vimscript-performance/
Saturday, December 22, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment