Christian Brabandt wrote:
> On So, 23 Dez 2012, Marco wrote:
>
> > 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?
>
> Bram,
> foldupdate will be called several times, when formating a paragraph,
> because it can be called in del_bytes() function and also in do_join()
> function. I wonder, if we can defer the foldupdate until after
> formatting has taken place, e.g. something like this patch, which seems
> to work so far, but the foldexpression is called not so often.
When making changes to foldupdate, please test this in various
circumstances. In the past quite a few bugs were fixed because folds
were not updated properly. I'm not sure postponing the update works
properly.
--
Some of the well known MS-Windows errors:
EMULTI Multitasking attempted, system confused
EKEYBOARD Keyboard locked, try getting out of this one!
EXPLAIN Unexplained error, please tell us what happened
EFUTURE Reserved for our future mistakes
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment