[patch] fix very slow syntax highlight in runtime/syntax/vim.vim (to be reviewed)

190 views
Skip to first unread message

Dominique Pellé

unread,
Aug 16, 2012, 3:46:21 PM8/16/12
to vim_dev, Charles Campbell
Hi

":help todo.txt" contains this item:

===
This line hangs Vim, because of syntax HL:
call append(line, "INFO
....12....18....24....30....36....42....48....54....60....66....72....78%$")
===

It does not really hangs, it's just very very slow. With a shorter string,
you can see it being slow without hanging, but it gets very slow with
long string.

I found that it happens because of the vimFunc regexp in
runtime/syntax/vim.vim which causes a backtracking explosion
with consecutive dots I think.

If I replace ...

\%([a-zA-Z0-9_.]\+\.\)

... into...

\%([a-zA-Z0-9_]\+\.\)

... then syntax highlighting is instantaneous.
See attached patch.

I'm not sure whether there are side effects.
So perhaps there is a better way to fix it.
But patch should at least help to diagnose the issue.

I CC Charles who maintains the vim.vim syntax file for review.

Regards
-- Dominique
fix-slow-syntax-highlight-vim.vim-7.3.633.patch

Bram Moolenaar

unread,
Aug 17, 2012, 4:24:13 PM8/17/12
to Dominique Pellé, vim_dev, Charles Campbell

Dominique Pelle wrote:

> ":help todo.txt" contains this item:
>
> ===
> This line hangs Vim, because of syntax HL:
> call append(line, "INFO
> ....12....18....24....30....36....42....48....54....60....66....72....78%$")
> ===
>
> It does not really hangs, it's just very very slow. With a shorter string,
> you can see it being slow without hanging, but it gets very slow with
> long string.
>
> I found that it happens because of the vimFunc regexp in
> runtime/syntax/vim.vim which causes a backtracking explosion
> with consecutive dots I think.
>
> If I replace ...
>
> \%([a-zA-Z0-9_.]\+\.\)
>
> ... into...
>
> \%([a-zA-Z0-9_]\+\.\)
>
> ... then syntax highlighting is instantaneous.
> See attached patch.

This is a typical example where the NFA regexp code would avoid the
problem. I'm still waiting for someone to pick up the work, which
mainly involves writing tests and only switching to NFA if we know the
regexp will be executed correctly.

--
hundred-and-one symptoms of being an internet addict:
253. You wait for a slow loading web page before going to the toilet.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages