Skip to content

Instantly share code, notes, and snippets.

@azirbel
Last active February 12, 2016 19:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save azirbel/d89523b1d0e4f1652072 to your computer and use it in GitHub Desktop.
Slight vim slowness while scrolling a large file
FUNCTION AutoSave()
Called 6 times
Total time: 0.000601
Self time: 0.000601
count total (s) self (s)
6 0.000072 if g:auto_save >= 1
6 0.000109 let was_modified = &modified
6 0.000021 if g:auto_save_keep_marks >= 1
6 0.000113 let first_char_pos = getpos("'[")
6 0.000042 let last_char_pos = getpos("']")
6 0.000022 silent! wa
6 0.000036 call setpos("'[", first_char_pos)
6 0.000019 call setpos("']", last_char_pos)
6 0.000010 else
silent! wa
endif
6 0.000013 if was_modified && !&modified
if exists("g:auto_save_postsave_hook")
execute "" . g:auto_save_postsave_hook
endif
if g:auto_save_silent == 0
echo "(AutoSaved at " . strftime("%H:%M:%S") . ")"
endif
endif
6 0.000006 endif
FUNCTION wintabs#refresh_buflist()
Called 397 times
Total time: 0.053079
Self time: 0.019924
count total (s) self (s)
397 0.002051 let window = a:window == 0 ? winnr() : a:window
" load buflist from saved value
397 0.005341 0.002510 let buflist = wintabs#getwinvar(window, 'wintabs_buflist', [])
" remove stale bufs
397 0.015103 0.006431 call filter(buflist, 's:buflisted(v:val)')
" add current buf
397 0.001050 let current_buffer = winbufnr(window)
397 0.001460 if index(buflist, current_buffer) == -1 && s:buflisted(current_buffer)
call add(buflist, current_buffer)
endif
" save buflist
397 0.001478 call setwinvar(window, 'wintabs_buflist', buflist)
" save this to session
397 0.023334 0.001681 call wintabs#session#save(tabpagenr(), window)
FUNCTION wintabs#ui#get_statusline()
Called 397 times
Total time: 0.156476
Self time: 0.009069
count total (s) self (s)
397 0.102011 0.004209 let bufline = s:get_bufline(a:window)
397 0.051812 0.002207 let line = s:truncate_line(a:window, bufline, winwidth(a:window))
" reseter is attached to detect stale status
397 0.001057 let reseter = '%{wintabs#ui#reset_statusline('.a:window.')}'
397 0.000557 return reseter.line
FUNCTION <SNR>37_truncate_line()
Called 397 times
Total time: 0.049605
Self time: 0.048544
count total (s) self (s)
397 0.001396 let [line, active_start, active_end, active_higroup_len] = a:bufline
" load line_start from saved value
397 0.002487 0.001426 let line_start = wintabs#getwinvar(a:window, 'wintabs_bufline_start', 0)
" inflate width by length of higroup markers
397 0.000966 let inflated_width = a:width + active_higroup_len
397 0.000525 let width = inflated_width
" arrows are added to indicate truncation
397 0.000454 let left_arrow = 0
397 0.000421 let right_arrow = 0
397 0.000909 let left_arrow_len = len(g:wintabs_ui_arrow_left)
397 0.000872 let right_arrow_len = len(g:wintabs_ui_arrow_right)
" adjust line_start and width to accommodate actie buffer and arrows
" 3 passes are needed to satisfy enough constraints
1588 0.001756 for i in range(3)
" line_start <= active_start < active_end <= line_start + width
1191 0.001411 if active_start < active_end
1191 0.001270 if line_start > active_start
let line_start = active_start
endif
1191 0.001656 if active_end > line_start + width
let line_start = active_end - width
endif
1191 0.000557 endif
" check if left arrow is needed
1191 0.001332 if !left_arrow && line_start > 0
let left_arrow = 1
let width -= left_arrow_len
endif
" check if right arrow is needed
1191 0.002533 if !right_arrow && line_start + width < len(line)
let right_arrow = 1
let width -= right_arrow_len
elseif right_arrow && line_start + width >= len(line)
let right_arrow = 0
let width += right_arrow_len
endif
1191 0.000598 endfor
" if it's at the end of bufline, try to expand as much as possible
397 0.000443 if left_arrow && !right_arrow
let width = inflated_width
let line_start = len(line) - width
if line_start <= 0
let left_arrow = 0
let line_start = 0
else
let left_arrow = 1
let line_start += left_arrow_len
endif
endif
" save line_start
397 0.001309 call setwinvar(a:window, 'wintabs_bufline_start', line_start)
" final assembly
397 0.000737 let left = left_arrow ? g:wintabs_ui_arrow_left : ''
397 0.000699 let right = right_arrow ? g:wintabs_ui_arrow_right : ''
397 0.001399 let line = left.strpart(line, line_start, width).right
397 0.000358 return line
FUNCTION wintabs#getbufvar()
Called 397 times
Total time: 0.002085
Self time: 0.002085
count total (s) self (s)
397 0.001844 return getbufvar(a:buf, a:key, a:def)
FUNCTION <SNR>35_session_save_window()
Called 397 times
Total time: 0.009118
Self time: 0.009118
count total (s) self (s)
397 0.001482 let s:session[a:tabpage][a:window] = []
397 0.001418 let buflist = gettabwinvar(a:tabpage, a:window, 'wintabs_buflist', [])
" bufnr isn't persisted across sessions, but bufname is
794 0.001352 for buffer in buflist
397 0.002420 call add(s:session[a:tabpage][a:window], bufname(buffer))
397 0.000384 endfor
FUNCTION xolox#misc#cursorhold#autocmd()
Called 6 times
Total time: 0.001120
Self time: 0.000947
count total (s) self (s)
" The 'top level event handler' that's called by Vim whenever the
" [CursorHold][] or [CursorHoldI][] event fires. It iterates through the
" event handlers registered using `xolox#misc#cursorhold#register()` and
" calls each event handler at the appropriate interval, keeping track of
" the time when each event handler was last run.
12 0.000047 for handler in g:xolox#misc#cursorhold#handlers
6 0.000029 let function = handler['function']
6 0.000030 let last_run = get(handler, 'last_run', 0)
6 0.000021 let interval = get(handler, 'interval', 4)
6 0.000191 0.000087 call xolox#misc#msg#debug("vim-misc %s: Checking handler %s with interval %i and last run %i ..", g:xolox#misc#version, function, interval, last_run)
" Rate limit in case &updatetime is set (very) low.
6 0.000051 let time_until_next_run = (last_run + interval) - localtime()
6 0.000013 if time_until_next_run > 0
6 0.000403 0.000333 call xolox#misc#msg#debug("vim-misc %s: Rate limiting handler %s (time until next run: %i seconds).", g:xolox#misc#version, function, time_until_next_run)
6 0.000007 else
call xolox#misc#msg#debug("vim-misc %s: Running handler %s ..", g:xolox#misc#version, function)
call call(function, get(handler, 'arguments', []))
let handler['last_run'] = localtime()
endif
6 0.000009 endfor
FUNCTION wintabs#ui#reset_statusline()
Called 397 times
Total time: 0.002077
Self time: 0.002077
count total (s) self (s)
" reset statusline if its assigned winnr is stale
397 0.000688 if a:window != winnr()
call wintabs#ui#set_statusline()
endif
397 0.000251 return ''
FUNCTION xolox#misc#msg#debug()
Called 12 times
Total time: 0.000173
Self time: 0.000173
count total (s) self (s)
" Show a formatted debugging message to the user, *if the user has enabled
" increased verbosity by setting Vim's ['verbose'] [] option to one
" (1) or higher*.
"
" This function has the same argument handling as the
" `xolox#misc#msg#info()` function.
"
" In the case of `xolox#misc#msg#debug()`, automatic string coercion
" provides lazy evaluation in the sense that complex data structures are
" only converted to strings when the user has enabled increased verbosity.
"
" ['verbose']: http://vimdoc.sourceforge.net/htmldoc/options.html#'verbose'
12 0.000029 if &vbs >= 1
call s:show_message('Question', a:000)
endif
FUNCTION <SNR>36_buflisted()
Called 397 times
Total time: 0.008672
Self time: 0.006586
count total (s) self (s)
397 0.004093 0.002008 let filetype = wintabs#getbufvar(a:buffer, '&filetype', '')
397 0.001639 let ignored = index(g:wintabs_ignored_filetypes, filetype) != -1
397 0.001527 let empty = bufname(a:buffer) == '' && !wintabs#getbufvar(a:buffer, '&modified', '')
397 0.000950 return buflisted(a:buffer) && !ignored && !empty
FUNCTION wintabs#session#save()
Called 397 times
Total time: 0.021652
Self time: 0.012535
count total (s) self (s)
" if tabpages count is correct, refresh passed tabpages, otherwise refresh all
" tabpages
397 0.001265 if len(s:session) == tabpagenr('$')
397 0.001123 if !has_key(s:session, a:tabpage)
let s:session[a:tabpage] = {}
endif
" if windows count is correct, refresh passed window, otherwise refresh all
" windows
397 0.001369 if len(s:session[a:tabpage]) == winnr('$')
397 0.010827 0.001709 call s:session_save_window(a:tabpage, a:window)
397 0.000280 else
" this occurs on closing window
call s:session_save_tabpage(a:tabpage)
endif
397 0.000260 else
" this occurs on closing tabpage
call s:session_save_all()
endif
" serialize to session global
397 0.001986 let g:Wintabs_session_string = string(s:session)
FUNCTION wintabs#getwinvar()
Called 1191 times
Total time: 0.005009
Self time: 0.005009
count total (s) self (s)
1191 0.004368 return getwinvar(a:winnr, a:key, a:def)
FUNCTION <SNR>37_get_bufline()
Called 397 times
Total time: 0.097802
Self time: 0.043606
count total (s) self (s)
397 0.055224 0.002145 call wintabs#refresh_buflist(a:window)
397 0.000764 let line = g:wintabs_ui_sep_leftmost
397 0.001037 let seplen = len(g:wintabs_ui_sep_inbetween)
397 0.000543 let active_start = 0
397 0.000418 let active_end = 0
397 0.000497 let active_higroup_len = 0
794 0.002952 0.001835 for buffer in wintabs#getwinvar(a:window, 'wintabs_buflist', [])
" get buffer name and normalize
397 0.001445 let name = fnamemodify(bufname(buffer), ':t')
397 0.002285 let name = substitute(name, '%', '%%', 'g')
397 0.000516 if name == ''
let name = '[No Name]'
endif
397 0.000969 if getbufvar(buffer, '&readonly', '')
let name = name.g:wintabs_ui_readonly
elseif getbufvar(buffer, '&modified', '')
let name = name.g:wintabs_ui_modified
endif
397 0.000714 let name = ' '.name.' '
" highlight current buffer
397 0.000699 if buffer == winbufnr(a:window)
" remove last 'inbetween' separator or 'leftmost' separator
397 0.000545 if line == g:wintabs_ui_sep_leftmost
397 0.000472 let line = ''
397 0.000213 else
let line = line[:-(seplen+1)]
endif
" add active tab markers and highlight group
397 0.001045 let name = g:wintabs_ui_active_left.name.g:wintabs_ui_active_right
397 0.001071 let name = '%#'.g:wintabs_ui_active_higroup.'#'.name.'%##'
" save position of current buffer
397 0.000883 let active_start = len(line)
397 0.000855 let active_end = len(line.name)
397 0.000935 let active_higroup_len = len('%##%##'.g:wintabs_ui_active_higroup)
397 0.000197 else
let name = name.g:wintabs_ui_sep_inbetween
endif
397 0.000534 let line = line.name
397 0.000292 endfor
397 0.000596 if line == g:wintabs_ui_sep_leftmost
" remove separators if buflist is empty
let line = ''
elseif line[-3:] != '%##'
" change last 'inbetween' separator to 'rightmost'
let line = line[:-(seplen+1)].g:wintabs_ui_sep_rightmost
endif
397 0.000983 return [line, active_start, active_end, active_higroup_len]
FUNCTION <SNR>73_Highlight_Matching_Pair()
Called 382 times
Total time: 0.019487
Self time: 0.019487
count total (s) self (s)
" Remove any previous match.
382 0.001263 if exists('w:paren_hl_on') && w:paren_hl_on
silent! call matchdelete(3)
let w:paren_hl_on = 0
endif
" Avoid that we remove the popup menu.
" Return when there are no colors (looks like the cursor jumps).
382 0.001223 if pumvisible() || (&t_Co < 8 && !has("gui_running"))
return
endif
" Get the character under the cursor and check if it's in 'matchpairs'.
382 0.001039 let c_lnum = line('.')
382 0.000795 let c_col = col('.')
382 0.000506 let before = 0
382 0.001138 let text = getline(c_lnum)
382 0.000944 let c = text[c_col - 1]
382 0.004135 let plist = split(&matchpairs, '.\zs[:,]')
382 0.001038 let i = index(plist, c)
382 0.000391 if i < 0
" not found, in Insert mode try character before the cursor
382 0.000837 if c_col > 1 && (mode() == 'i' || mode() == 'R')
let before = 1
let c = text[c_col - 2]
let i = index(plist, c)
endif
382 0.000287 if i < 0
" not found, nothing to do
382 0.000297 return
endif
endif
" Figure out the arguments for searchpairpos().
if i % 2 == 0
let s_flags = 'nW'
let c2 = plist[i + 1]
else
let s_flags = 'nbW'
let c2 = c
let c = plist[i - 1]
endif
if c == '['
let c = '\['
let c2 = '\]'
endif
" Find the match. When it was just before the cursor move it there for a
" moment.
if before > 0
let has_getcurpos = exists("*getcurpos")
if has_getcurpos
" getcurpos() is more efficient but doesn't exist before 7.4.313.
let save_cursor = getcurpos()
else
let save_cursor = winsaveview()
endif
call cursor(c_lnum, c_col - before)
endif
" Build an expression that detects whether the current cursor position is in
" certain syntax types (string, comment, etc.), for use as searchpairpos()'s
" skip argument.
" We match "escape" for special items, such as lispEscapeSpecial.
let s_skip = '!empty(filter(map(synstack(line("."), col(".")), ''synIDattr(v:val, "name")''), ' . '''v:val =~? "string\\|character\\|singlequote\\|escape\\|comment"''))'
" If executing the expression determines that the cursor is currently in
" one of the syntax types, then we want searchpairpos() to find the pair
" within those syntax types (i.e., not skip). Otherwise, the cursor is
" outside of the syntax types and s_skip should keep its value so we skip any
" matching pair inside the syntax types.
execute 'if' s_skip '| let s_skip = 0 | endif'
" Limit the search to lines visible in the window.
let stoplinebottom = line('w$')
let stoplinetop = line('w0')
if i % 2 == 0
let stopline = stoplinebottom
else
let stopline = stoplinetop
endif
" Limit the search time to 300 msec to avoid a hang on very long lines.
" This fails when a timeout is not supported.
if mode() == 'i' || mode() == 'R'
let timeout = exists("b:matchparen_insert_timeout") ? b:matchparen_insert_timeout : g:matchparen_insert_timeout
else
let timeout = exists("b:matchparen_timeout") ? b:matchparen_timeout : g:matchparen_timeout
endif
try
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, timeout)
catch /E118/
" Can't use the timeout, restrict the stopline a bit more to avoid taking
" a long time on closed folds and long lines.
" The "viewable" variables give a range in which we can scroll while
" keeping the cursor at the same position.
" adjustedScrolloff accounts for very large numbers of scrolloff.
let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
" one of these stoplines will be adjusted below, but the current values are
" minimal boundaries within the current window
if i % 2 == 0
if has("byte_offset") && has("syntax_items") && &smc > 0
let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
let stopline = min([bottom_viewable, byte2line(stopbyte)])
else
let stopline = min([bottom_viewable, c_lnum + 100])
endif
let stoplinebottom = stopline
else
if has("byte_offset") && has("syntax_items") && &smc > 0
let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
let stopline = max([top_viewable, byte2line(stopbyte)])
else
let stopline = max([top_viewable, c_lnum - 100])
endif
let stoplinetop = stopline
endif
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
endtry
if before > 0
if has_getcurpos
call setpos('.', save_cursor)
else
call winrestview(save_cursor)
endif
endif
" If a match is found setup match highlighting.
if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom
if exists('*matchaddpos')
call matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10, 3)
else
exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
endif
let w:paren_hl_on = 1
endif
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
397 0.156476 0.009069 wintabs#ui#get_statusline()
397 0.097802 0.043606 <SNR>37_get_bufline()
397 0.053079 0.019924 wintabs#refresh_buflist()
397 0.049605 0.048544 <SNR>37_truncate_line()
397 0.021652 0.012535 wintabs#session#save()
382 0.019487 <SNR>73_Highlight_Matching_Pair()
397 0.009118 <SNR>35_session_save_window()
397 0.008672 0.006586 <SNR>36_buflisted()
1191 0.005009 wintabs#getwinvar()
397 0.002085 wintabs#getbufvar()
397 0.002077 wintabs#ui#reset_statusline()
6 0.001120 0.000947 xolox#misc#cursorhold#autocmd()
6 0.000601 AutoSave()
12 0.000173 xolox#misc#msg#debug()
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
397 0.049605 0.048544 <SNR>37_truncate_line()
397 0.097802 0.043606 <SNR>37_get_bufline()
397 0.053079 0.019924 wintabs#refresh_buflist()
382 0.019487 <SNR>73_Highlight_Matching_Pair()
397 0.021652 0.012535 wintabs#session#save()
397 0.009118 <SNR>35_session_save_window()
397 0.156476 0.009069 wintabs#ui#get_statusline()
397 0.008672 0.006586 <SNR>36_buflisted()
1191 0.005009 wintabs#getwinvar()
397 0.002085 wintabs#getbufvar()
397 0.002077 wintabs#ui#reset_statusline()
6 0.001120 0.000947 xolox#misc#cursorhold#autocmd()
6 0.000601 AutoSave()
12 0.000173 xolox#misc#msg#debug()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment