Skip to content

Commit

Permalink
cache location of session file
Browse files Browse the repository at this point in the history
Function session_file() returns the name of session file.
This function is called for every change in VIM layout.

Caching of return variable of this function gives x100 performance
improvement.

Before change:
FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    6   3.369383   0.015592  g:GitSessionUpdate()
    6   3.353791   0.000861  <SNR>35_session_file()
    6   3.268404   0.001057  <SNR>35_session_dir()
   12   3.263580   0.004735  <SNR>35_in_git_repo()

After this change:
FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
   11   0.026195             g:GitSessionUpdate()
   23   0.025646             <SNR>38_Highlight_Matching_Pair()
   11   0.000956             nerdtree#checkForBrowse()

VIM profiling (http://stackoverflow.com/a/12216578):
	:profile start profile.log
	:profile func *
	:profile file *
	" At this point do slow actions
	:profile pause
	:noautocmd qall!

Signed-off-by: Leon Romanovsky <leon@leon.nu>
  • Loading branch information
rleon committed Jul 23, 2015
1 parent 654a569 commit 385d380
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions plugin/gitsessions.vim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ endfunction

function! g:GitSessionSave()
let l:dir = s:session_dir()
let l:file = s:session_file()

if !isdirectory(l:dir)
call mkdir(l:dir, 'p')
Expand All @@ -126,24 +125,23 @@ function! g:GitSessionSave()
endif

let s:session_exist = 1
if filereadable(l:file)
execute 'mksession!' l:file
echom "session updated:" l:file
if filereadable(s:s_file)
execute 'mksession!' s:s_file
echom "session updated:" s:s_file
else
execute 'mksession!' l:file
echom "session saved:" l:file
execute 'mksession!' s:s_file
echom "session saved:" s:s_file
endif
redrawstatus!
endfunction

function! g:GitSessionUpdate(...)
let l:show_msg = a:0 > 0 ? a:1 : 1
let l:file = s:session_file()

if s:session_exist && filereadable(l:file)
execute 'mksession!' l:file
if s:session_exist && filereadable(s:s_file)
execute 'mksession!' s:s_file
if l:show_msg
echom "session updated:" l:file
echom "session updated:" s:s_file
endif
endif
endfunction
Expand All @@ -154,32 +152,35 @@ function! g:GitSessionLoad(...)
endif

let l:show_msg = a:0 > 0 ? a:1 : 0
let l:file = s:session_file()

if filereadable(l:file)
if filereadable(s:s_file)
let s:session_exist = 1
execute 'source' l:file
echom "session loaded:" l:file
execute 'source' s:s_file
echom "session loaded:" s:s_file
elseif l:show_msg
echom "session not found:" l:file
echom "session not found:" s:s_file
endif
redrawstatus!
endfunction

function! g:GitSessionDelete()
let l:file = s:session_file()
let s:session_exist = 0
if filereadable(l:file)
call delete(l:file)
echom "session deleted:" l:file
if filereadable(s:s_file)
call delete(s:s_file)
echom "session deleted:" s:s_file
endif
endfunction

function! g:GitCacheVariables()
let s:s_file = s:session_file()
endfunction

augroup gitsessions
autocmd!
if ! exists("g:gitsessions_disable_auto_load")
autocmd VimEnter * :call g:GitSessionLoad()
endif
call g:GitCacheVariables()
autocmd BufEnter * :call g:GitSessionUpdate(0)
autocmd VimLeave * :call g:GitSessionUpdate()
augroup END
Expand Down

0 comments on commit 385d380

Please sign in to comment.