todesking / ruby_hl_lvar.vim

Highlight Ruby local variables
MIT License
53 stars 10 forks source link

Improve performance by matchaddpos() #9

Closed pocke closed 9 years ago

pocke commented 9 years ago

This patch improves performance by using matchaddpos() function, which is available Vim 7.4.330 or later, if available. http://vim-jp.org/vimmagazine/2014/06/30/vimmagazine.html

matchaddpos() is significantly faster than matchadd(). https://github.com/vim/vim/blob/master/runtime/doc/eval.txt#L4442 Vim is particularly faster when moving the cursor.

benchmark

function! Test()
  call cursor(1, 1)
  let t = reltime()
  for i in range(1, line('$'))
    call cursor(i, 1)
    redraw
  endfor
  echom reltimestr(reltime(t))
endfunction

function! SetBuf()
  for _ in range(1, 100)
    call append('$', 'a, b, c, d, e, f, g, h, i, j, k, l = nil')
  endfor

  let g:ruby_hl_lvar_hl_group = 'Error'

  set rtp+=~/.vim/bundle/ruby_hl_lvar.vim/

  filetype plugin indent on
  syntax enable
endfunction

call SetBuf()

Save the above as test.vim, and run the following command.

vim -u test.vim -N -c 'set ft=ruby' -c 'call Test()'

Before patch(ef2b4a2486d1f84e5e056ac302551afa66c2f5d6)

1.492471 sec

After patch

0.095837 sec

todesking commented 9 years ago

Seems OK :+1: