Wednesday, May 24, 2017

Re: Bug in ftdetect?

On Mi, 24 Mai 2017, fREW Schmidt wrote:

> Yes. "If I replace the contents of /usr/share/vim/vim80/syntax/vb.vim with `let
> b:current_syntax = "vb"` everything is fast and, as I would hope, the support
> files are not loaded N times per buffer but instead exactly once." 

Well, I see the problem, although I cannot reproduce it.

The markdown syntax script sources the html syntax script and that one
does include a couple of other syntax scripts, like css.vim,
javascript.vim and also vb.vim. However from my testing vb.vim is not
guilty alone. If I uncomment vb.vim, the overall loading time only
shrinks by 0.2 seconds or so (it needs here a total of around 7
seconds). So you would need to disable all other to be included syntax
scripts as well (for a test, you could set main_syntax='java').

However, I think you might have found a bug here. Your ftdetect script
does this:

autocmd BufNew,BufNewFile,BufRead *.md :set filetype=markdown

The :args command does fill the argument list, calls ex_next() which
calls eventually alist_set() and then iterates over the argument list
and calls adlist_add(). This will finally call buflist_add() which in
turn calls buflist_new(), which triggers the BufNew autocommand, which
then triggers the FileType and finally the Syntax autocommands. So in
the end, we are iterating over the whole list of arguments and call
autocommands, for buffers that are not even going to be displayed next.

So I wonder, if we can't do a little bit better, similar to how vimgrep
sets the eventignore option to prevent at least the expensive FileType
autocommand:

diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 36ee57e8e..e0fbbfb9b 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -2757,8 +2757,22 @@ ex_next(exarg_T *eap)
{
if (*eap->arg != NUL) /* redefine file list */
{
+ /* do_arglist() could trigger BufNew events, which might
+ * in turn trigger expensive FileType and Syntax autocommands
+ * prevent this for now */
+#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
+ char_u *save_ei = au_event_disable(",Filetype");
+

No comments:

Post a Comment